在后台运行带有计时器的功能

时间:2017-12-22 11:39:55

标签: ios objective-c notifications

我想在应用程序进入后台后运行一个函数,这将启动本地通知,我做的是以下内容:

- (void)applicationDidEnterBackground:(UIApplication *)application {
    UIApplication* app = [UIApplication sharedApplication];
    __block UIBackgroundTaskIdentifier bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
        bgTask = UIBackgroundTaskInvalid;
        [NSTimer scheduledTimerWithTimeInterval:30.0f target:self selector:@selector(triggerLocalNotification) userInfo:nil repeats:YES];
    }];

   }

仅当iPhone连接到MacBook时才有效,如果我们断开它并运行应用程序,则此功能未被调用。 有什么帮助吗?

0 个答案:

没有答案