当应用程序处于后台时,连续更新UILabel当前时间

时间:2013-12-02 13:07:55

标签: ios7 uilabel xcode5 nstimer background-process

当我尝试在后台应用期间使用当前时间更新UILabel时,标签不会更新。它适用于xCode 4.6.2,但是当xCode 5 iOS 7没有更新时。

NSTimer *preventSleepTimer = [[NSTimer alloc] initWithFireDate:[NSDate date] interval:5.0 target:self selector:@selector(mmp_playPreventSleepSound) userInfo:nil repeats:YES];

我正在调用“mmp_playPreventSleepSound”这个方法每隔5秒就会调用一次,但它不会调用此方法,并且应用会在5分钟后终止。

请给我一个解决方案,以便我可以在后台更新UILabel文字,应用程序应该连续投放?

1 个答案:

答案 0 :(得分:0)

这不是一个好主意。你应该实现方法

- (void)applicationWillEnterForeground:(UIApplication *)application
- (void)applicationDidBecomeActive:(UIApplication *)application

当应用程序进入前台时,您可以更新标签

如果您想在后台播放音频,请使用AV Foundation https://developer.apple.com/library/ios/qa/qa1668/_index.html