我正在尝试在应用程序转到后台时实现某些应用程序功能 . 但是我看到一个奇怪的问题,如果我在“applicationDidEnterBackground”中使用NSTimer每2秒做一次NSLog,使用模拟器它可以工作,但是当我在实际设备中测试它时,它不会打印 . 以下是我的“AppDelegate.m”代码:

- (void)printLog
{
    NSLog(@"logging after 2 sec.");
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    bckTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(printLog) userInfo:nil repeats:YES];
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [bckTimer invalidate];
}

请让我知道为什么会发生这种情况,并且可能是您在使用后台应用功能执行时想要分享的任何提示 .

谢谢