Forcing a WWAN connection on iPhone, even when Wi-Fi is available - iphone

I need to make a network connection over WWAN (i.e. the mobile network) on an iPhone, even when the device is connected to a Wi-Fi network, however I can't find a way to do this.
I've tried going down to the socket level and iterating through the available interfaces, however when connected to Wi-Fi, the WWAN interface (pdp_ip0) disappears.
The solution needs to be App Store safe.

Enumerate the network interfaces, you will see that when you're connected on both wifi and 3g, there are 2 with different local ip addresses. You might be able to use one vs the other by forcing a bind of your socket on the right interface before sending the data. The kernel which tries to find the best interface to route your packet should be happy with your choice.
Disclaimer: I have not tried this, this is just a suggestion.

Perhaps you can use the Reachability code to determine if Wi-Fi is enabled, firing a UIAlertView to warn the users to quit the app, open the Settings app and switch off wireless manually. Not ideal, definitely.

There is no supported way to to do this. You need to tell the user to turn off the WiFi connection since "It's a non-negotiable operational requirement for the service the app needs to connect to."
In this scenario, the user is not likely to kill you with bad reviews if you are clear about why they have to disable WiFi.
-t

Related

iPhone as proxy for data upload

I want to create an iPhone application that can call web services on a computer, and then upload those files over the iPhone 3g connection. Is there an elegant way to do this?
I tried connecting the phone to local Wifi, but connecting to Wifi disables 3g, even though the Wifi is local network only.
I assume the same problem would arise if I could network the phone with the computer via bluetooth.
Any other ideas? The purpose is to go up to a special demo PC we created, pull some data off, then upload to the Internet, all within proximity of the machine. Unfortunately, it appears that I can't use one connection for pulling data, and another for pushing.
Your assumption is correct. When connecting to both 3G and Wifi, the Wifi connection will be used. Sounds like your local network has no route to the Internet. Perhaps that could be fixed.
Apple does not prefer its iPhones to be used as routers.
If you're working on something that will not be distributed through the App Store, you may have some success looking at "tethering" applications and their source code, which can be found by some clever Googling.

Can I use only cellular network (3G or EDGE), even if WIFI is connected on the iPhone?

I was wondering whether I can use the cellular network (3G or 2G or whatever they may have) even if the WIFI is connected and working.
I noticed that Apple has a "Reachability" sample code, but that would only tell me if I can connect using a cellular network; instead, I would like to actually use ONLY the cellular network.
Best Regards,
Noam.
Definitely YES. You should combine Reachability notifications with network interfaces enumeration. And - this point is much important: use BSD socket's bind() call to bind to CONCRETE IP address. Don't use 0.0.0.0 and your app will be network-adaptive and awaring. My poor gist example: https://gist.github.com/avesus/fdb465b60a4f5204845c
No, I wouldn't imagine so.
My understanding is that if the device is connected to Wifi, 3G is not used for data and all data traffic travels via Wifi.
Only cellular data to another cellular device would use the phone provider's network.
I believe that the only way to accomplish this would be to detect if the user is on WiFi (example code is in the "Reachability" example you cited), and if so, prompt them to disable WiFi prior to using your app.

Any iPhone SDK API available to promote 3G/GPRS over WiFi in an iPhone application

I have a requirement to promote 3G/GPRS over WiFi connectivity in the iPhone application I am developing. Please let me know if this is possible and if yes, how?
The problem is when I have a WiFi network which is available and connected but not logged in using Captive Portal, I cannot use that WiFi network to perform the tasks which require internet connection. What i have noticed is Reachability API detects the available WiFi but I cannot use it as I am not logged in and so I am not connected to internet using this WiFi hotspot until I login. So I want to use 3G/GPRS to perform the tasks requiring internet connectivity.
iPhone's default behavior is it uses WiFi when its available and if not then only 3G/GPRS.
So please let me know if both 3G/GPRS and WiFi are available but I am connected to internet not using WiFi but 3G/GPRS how to use 3G/GRPS to perform the tasks requiring internet connectivity.
Regards,
Third-party applications don't get control of where their data comes from. About all you're going to be able to do is ask your users to turn wifi off while your application does its thing. If you need to get back onto wifi after doing the initial data transfer, you could make some clever use of the iOS 4 multitasking and local-notification APIs: when your application enters the background, it could start a background-task handler (using -beginBackgroundTaskWithExpirationHandler: in your app delegate's -applicationDidEnterBackground:) to wait for the wifi connection to become unavailable, do its thing with the cell network, then create a UILocalNotification to tell the user it's okay to turn wifi back on again. That way, the user could get the benefits of whatever your app does and still keep the connection they started out on.
If you are creating an app which needs to access certain network resource(s) to function, then you should just ping, or try to connect to those resources directly instead of just depending on reachability for the decision. If you can't ping your server, then have the app do the same thing it would if reachability reported zero connectivity (even though it may not be).
For security reasons, Apple doesn't allow developer to do such settings pro grammatically, despite you GPRS network connection to achieve some purposes.

How does iPhone app communicate with other devices?

We bought a Grace wifi radio. Grace has a cool iPhone app that connects to the radio and lets you control it.
My question is.. how the heck does this work? How can the iPhone connect to the radio and then control it??
I can't find detailed technical information on Grace's side, but, if I were asked to design something like this, I'd have the radio advertise a service on its wifi LAN via zeroconf (also known by Apple's trademarked name, bonjour -- an app on the iphone (or any other node on that wifi LAN) can then easily find the radios on the same LAN and chat with them through whatever protocol Grace has defined for the purpose.
Edit: from the scarce crumbs of docs on Grace's site it seem they may have chosen UPnP instead of Zeroconf -- ah well, see here for a (possibly biased, but solid) analysis of why they should have chosen Zeroconf instead!-)
Are you asking coding specifics or just an overall concept of what's going on? The actual networking stack behind these operations can be quite complex.
Your Grace wifi radio will have created a server which the iPhone has connected to on your wifi network, from this point onwards it's a simple client-server relationship, with the iPhone sending data to the radio each time it sends a command. Because of this, if your iPhone is not on the same wifi network it will not be able to control/find the radio.
Most likely, the WiFi radio listens over a fixed UDP port. The iPhone in turn sets up a UDP connection by broadcasting the network (on IP 255.255.255.255) on that port. The radio will respond and a connection will be established.
This is complete speculation; I have no idea how it actually works. No doubt there is plenty of documentation on this.

How to list all devices in my wifi range in iphone

I am using the reachability code from apple to find if my iphone is connected to the wifi. Next i would like to list all the devices that are in my wifi range. How should i do this. The other devices do not publish any service. I want to detect all devices in my wifi range and send that device a request for tcp connection.
If a device does not advertise its presence and is not otherwise active, TCP/IP does not give you a way to "detect" it. If you can identify your subnet (which has nothing to do with a "wifi range", whatever that may be), you can try connecting to each possible host in it on all possible ports -- this is generally considered an attack (what legitimate reason could you have for such a port scan?), so, if you're detected trying this attack, be prepared for the consequences.
As #Alex says, even if you could find devices that weren't advertising, what's the point? You can't most likely do any adhoc communications with them. Instead you'd need to find copies of your application running on connected devices, and your app needs to advertise.
Take a look at Gamekit sample projects which will give you bluetooth connectivity, and you could dig into something like Jens Alfke's MyNetwork and Blip libraries for tcp/wifi. http://jens.mooseyard.com/2008/05/blip-come-n-get-it/