Is it Possible for an app to know whether the connection has been switched from Wi-Fi to 3G While app is in background?The requirement is that download should happen on Wi-Fi Connection.The Check is done initialy but i need to confirm that download is happening on Wi-Fi and should be cancelled if the user has switched to 3G/4G while app is in Background.
Asked
Active
Viewed 577 times
4
-
isn't the download canceled anyway, because your IP address has changed? – JeanLuc Apr 23 '14 at 09:21
-
So if im keeping a long runnning download process in background and if Wi-Fi goes and come backs after a few minutes will i be able to start the download in background itself? – Jacob Davis Cherussery Apr 23 '14 at 09:29
-
i don't know, try it! – JeanLuc Apr 23 '14 at 09:47
2 Answers
7
If you just want to make sure downloads only happen on WiFi, then you should set the allowsCellularAccess
property of the NSURLSession's NSURLSessionConfiguration to NO
.
No monitoring, cancelling or other tricks needed: that'll make sure the download never goes over the cellular connection.

Matt Gibson
- 37,886
- 9
- 99
- 128
0
I suggest you this library
It uses NSNotification, and you can make some changes in it if you need to set it your way
This is a example code provided by this library
// Allocate a reachability object
Reachability* reach = [Reachability reachabilityWithHostname:@"www.google.com"];
// Tell the reachability that we DON'T want to be reachable on 3G/EDGE/CDMA
reach.reachableOnWWAN = NO;
// Here we set up a NSNotification observer. The Reachability that caused the notification
// is passed in the object parameter
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChanged:)
name:kReachabilityChangedNotification
object:nil];
[reach startNotifier];
Hope it helps

E-Riddie
- 14,660
- 7
- 52
- 74
-
Will this notification be available while the app is still in background? – Jacob Davis Cherussery Apr 23 '14 at 09:23
-
1In fact I have no used the library when app is on background, since there are some limitations but have a look here for that issue http://stackoverflow.com/questions/5323634/ios-application-executing-tasks-in-background – E-Riddie Apr 23 '14 at 09:30
-
Im using NSURLSession to download the files.So the app is downloading large files in background. – Jacob Davis Cherussery Apr 23 '14 at 09:31
-
I checked some forums and tutorials and they say that https://developer.apple.com/library/ios/documentation/StoreKit/Reference/NewsstandKit_Framework/_index.html is the one for processing downloads on background, and you can manipulate it to work with NSNotifications on your own. Hope it hels – E-Riddie Apr 23 '14 at 09:55