How to change connection from 3G to wi-fi programmatically using iPhone SDK? - iphone

Lets consider that I am connected to internet through 3G in my App. When a wi-fi hot spot seems to be appearing, can I programmatically switch to the wi-fi. Is this vice-versa condition possible?

iOS does this automatically by itself!
If no known WiFi network is found, it uses cellular data. If it finds a known WiFi-network, it connects to and uses that network instead.
If any WiFi-network is found, and your application requests access to the internet, iOS (usually) automatically presents an alertView and lets the user log in to a WiFi-network. If the user does not log into a WiFi-network, it stays on the 3G-network. When iOS 7 comes, iOS may connect to Hotspot 2.0 networks automatically as well.
Apple keeps individual apps on a tight leash, and so they do not let apps control things like this.

Related

HttpUrlConnection on Android Wear with connected phone

I am trying to access the network with my Android Wear 2.0 App.
The Problem:
If the smartwatch is connected with the phone then I get an connection timeout. But if the smartwatch isnĀ“t connected with the phone then the connection works fine.
I am using HttpUrlConnection.
Thanks and sorry for my bad english!
This has been answered in a different post:
Android Wear 100% packet loss
The basic idea is that you should not count on having Wi-Fi on the watch. The user may disable Wi-Fi on the watch and then your application will not work on the watch. Instead you should use your companion phone app to connect to the internet. If the phone isn't connected to your watch then use Wi-Fi.
Even if you want your app to run on an LET enabled watch the user may have turned this off or may not have a SIM card installed. At this point the user will most likely still expect your app to work.
So depending on what it is you're working on, if you want your app to work even while connected to the phone, then make a companion app for the phone. If you want your watch app to be a stand-alone app but you still want to be able to access the internet even when the watch is connected to the phone then you're basically saying that you want to drain the user's battery by using Wi-Fi/LTE instead of going via Bluetooth through the phone to access the web.

How to detect all available Wifi networks and connect to one of them in an iOS app

In my iOS app, I want to detect all available wifi networks and then choose one network form the list and connect to it. The goal is to not open the Settings built in app to connect to a wifi, but to do it all in my app.
First, is this possible? If possible, please point me to what framework(s) and methods to use.
I have looked at the Reachability example, but that doesn't work for me because, I think, all it does is monitor the network state of the device.
I also looked at the Captive Network Support framework, and used the CNCopySupportedInterfaces function:
CFArrayRef allWifiNetworks = CNCopySupportedInterfaces();
NSLog(#"%#", allWifiNetworks);
but all I am seeing is the current wifi network that the device is connected to.
Thanks
I'm pretty sure you can't do this, at least not if you want to be able to publish on the App Store.

use 3g for internet when connected to adhoc wifi (using private API's)

First and foremost,
I am looking for a resource to use Private API's.
this is an enterprise application and will never go to the app store
I need to take as much configuration out of the users hands as possible.
That being said, I have a device that an ipad will be connected to and communicate with via an adhoc wifi network supplied by the device. the ipad connects to this device and sends raw data to it via socket connections. I also need to connect to the internet for data syncing.
80% of the time, the ipad will be connected to this adhoc wifi device. Management software on the ipad does not allow the user to adjust wifi settings so I am trying to make sure I am connected to my device without limiting my server syncing. I know I can determine the connection using apples Reachability class, this is not what i am looking for. I need to use BOTH 3g AND wifi.
Is there a way to enforce this in code? Or is there a resource for the private API's that I can look at to find a way?
This will be in iOS 5 and the most preferable method would be to just route my http requests via some private api method to use 3G and let the socket requests use wifi to the adhoc device.
code samples would be awesome, links / class names to research would be very much appreciated.
and once again this is not going into the app store, it is an enterprise app
the resolution i found was to assign an ip in the privately assigned ip range the ipad uses (169.254.x.x) to the adhoc device then let the ipad determine an ip. Then see if i can open a socket connection to the device (to determine if its available) and then issue a print.
Going this route, i am still able to use 3g data as well as communicate with the device via wifi.

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 to display a list of Wifi-Networks in an iPhone app?

I found some private (undocumented) APIs but Apple does not allow apps to use private frameworks. So does anyone know how to do this using Apple official packages?
like: when youtube app prompts you to the push notification: "Select a Wi-fi network"
Thanks in advance.
If you set the UIRequiresPersistentWiFi setting in your info.plist file, the iPhone OS will know that your app needs Wifi and pop up the message for you.
As far as I know, no app actually manually displays the wifi selection alert.
Thats wrong check this app out
http://itunes.apple.com/us/app/ihome-connect-setup-app-for/id450241802?mt=8
It shows available wifi networks
The best you can do in iOS, currently, is display the network the user is currently connected to. iOS doesn't allow you to access a wifi scan from within an app. I've been wrestling with this inability for some time now.
If designing an accessory that has WiFi, where you're trying to pass the user's WiFi network SSID and password, it will be up to the accessory to give the app that wifi scan list. The app can then display the list the accessory gave it to the user.
(I bet that's how the app #zaid pointed out in his answer, "iHome Connect", is doing it.)
Another approach is you could have a screen that prompts the user to enter the password to the wifi network they're connected to already, and then once the accessory is connected to the app, pass those details without the need for a wifi network list. I think that approach has a better user experience.
Plenty of stackoverflow questions that answer how to get the current wifi network, here's a couple:
Getting OSX Connected Wi-Fi Network Name
How do I get the current wifi network name after Yosemite in Swift?