. :
Project settings -> Capabilities -> BackgroundMode -> Background Fetch
, , , application:didFinishLaunchingWithOptions:, :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
return YES;
}
UIApplicationBackgroundFetchIntervalMinimum - smallest sampling interval supported by the system.
And then, when the background fetch is started, you can check AppDelegateusing the method:
-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
Reachability *reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];
NetworkStatus status = [reachability currentReachabilityStatus];
switch (status) {
case NotReachable: {
NSLog(@"no internet connection");
break;
}
case ReachableViaWiFi: {
NSLog(@"WiFi");
break;
}
case ReachableViaWWAN: {
NSLog(@"cellular");
break;
}
}
completionHandler(YES);
}
Support iOS 7.0 +
source
share