如何在iOS上执行倒计时器?
首先,我尝试NSTimer
。然后,当应用程序进入后台时,我发现NSTimer
无效。
其次,我用了
counterTask = [[UIApplication sharedApplication]
beg
inBackgroundTaskWithExpirationHandler:^{
}];
让NSTimer
在后台工作。但后来我发现iOS只允许应用程序在后台工作不超过600秒(10分钟)。我无法弄清楚如何让NSTimer
在背景中超过10分钟。
第三,我厌倦了使用NSLocalNotification
,而且效果很好。但我想做的是通过调用方法暂停播放音乐。我发现UILocalNotification
会在时间显示警报。如果您未单击警报按钮,则不会调用方法 - (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notification
。我不知道如何在不点击提醒按钮的情况下调用方法。
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notification {
NSLog(@"Recieved Notification %@",notification);
UIAlertView *alert=[[[UIAlertView alloc] initWithTitle:@"Local Notification" message:@"message"
delegate:nil cancelButtonTitle:nil
otherButtonTitles:nil, nil] autorelease];
[alert show];
}
所以,问题是
1.如何让NSTimer
在后台运行超过10分钟,
要么
2.当UILocalNotification
时间点击警报按钮时,如何调用我自己的方法。
非常感谢!
答案 0 :(得分:0)
counterTask = [[UIApplication sharedApplication]
beginBackgroundTaskWithExpirationHandler:^{
}];
在expiration处理程序中添加一些东西,它将生成另一个具有另一个到期处理程序的计时器,该处理程序使另一个计时器具有另一个处理程序...