`
zjjzmw1
  • 浏览: 1353597 次
  • 性别: Icon_minigender_1
  • 来自: 开封
社区版块
存档分类
最新评论

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

    博客分类:
  • iOS
 
阅读更多

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);

    }

 

}

 

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics