tags:

views:

428

answers:

3

Is it possible to restrict an iPhone app to only work if there's a Wifi connection (not 3G)?

A: 

Networking and Internet how-to's

If your application requires WiFi, you need to add the UIRequiresPersistentWiFi key to Info.plist and set it True. This key notifies the system that your application uses the WiFi network for communication.

Vladimir
+5  A: 

Yes. There are two steps:

First, you need to add the UIRequiresPersistentWiFi key to your applications Info.plist. This ensures that the WiFi connection does not go to sleep while your application is open.

Secondly, you need to query the system (using the SCNetworkReachability API) to see which radio is currently enabled. See this question in the iPhone documentation.

Stephen Darlington
-1. That doesn't restrict the app to only working on Wifi. That key allows your app to inform the system that it would prefer the wifi, and to keep it alive when the app is inactive (screen is locked, call in progress, etc). I use this key in my app, but I also allow 3G network access.
Jasarien
@Jasarien Yes, you're right, that doesn't directly answer the question. (Though saying that you _prefer_ WiFi over 3G is usually what people want.) I've updated my answer.
Stephen Darlington
Not exactly an answer to the question, but the best answer so far nonetheless.
hgpc
+2  A: 

You can also get the Reachability class from Reachability sample from apple dev center. It offers a way to check how the iphone is connected.

dusker
I would recommend this approach. You can specifically tell when the device is connected to wifi or not and restrict the parts of the app that require WiFi. The requires persistent wifi key will not fully restrict access to wifi only.
Jasarien