后台任务无效

时间:2015-09-08 07:26:27

标签: ios objective-c background uibackgroundtask

每当我的应用进入后台时,我都会尝试执行代码。但我的代码不起作用。这是我的以下代码:

- (void)applicationDidEnterBackground:(UIApplication *)application {
__block UIBackgroundTaskIdentifier bgTask;
NSLog(@"enter in background task");
UIApplication *app = [UIApplication sharedApplication];
NSLog(@"app is %@",app);
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
    NSLog(@"called function");
    [app endBackgroundTask:bgTask];
    bgTask = UIBackgroundTaskInvalid;
}]; }

但是我的代码无效。因为它不打印called function

提前致谢。

0 个答案:

没有答案