ios7 后台发送请求--每隔一段时间发送请求。

http://www.cocoachina.com/applenews/devnews/2013/1114/7350.html

在Capabilities -->background Modes --->打开。Background fetch

主要代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    // Override point for customization after application launch.

    

    [[UIApplicationsharedApplication] setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];

    returnYES;

}

 

 

 

 

-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

    

    UINavigationController *navigationController = (UINavigationController*)self.window.rootViewController;

    

    id topViewController = navigationController.topViewController;

//    [navigationController viewControllers];

    if ([topViewController isKindOfClass:[ViewController class]]) {

        [(ViewController*)topViewController insertNewObjectForFetchWithCompletionHandler:completionHandler];

    } else {

        NSLog(@"Not the right class %@.", [topViewController class]);

        completionHandler(UIBackgroundFetchResultFailed);

    }

 

}

 

 

 

 

 

 

猜你喜欢

转载自zhangmingwei.iteye.com/blog/2017023