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);
}
}
本文介绍如何在iOS应用中实现背景刷新功能,通过设置UIApplication的最小背景刷新间隔,并在应用执行刷新任务时调用特定方法来更新数据。文章还展示了如何判断当前视图控制器是否为期望类型并执行相应的刷新操作。
3987

被折叠的 条评论
为什么被折叠?



