Search code examples
iosnetwork-programmingbackground-processreachabilitynsurlsession

How to check if connection has been switched to 3G while app is in background in iOS?


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.


Solution

  • 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.