0

无论如何在应用程序终止后(不在后台)保持计时器运行。我想这样做,以便在计时器达到 0 时触发本地通知。

可以使用 UserDefaults 来实现这一点吗?

4

2 回答 2

1

猜你在谈论 iOS,看看这个: https ://developer.apple.com/library/ios/documentation/iphone/Reference/UILocalNotification_Class/Reference/Reference.html

NSTimer 不是你要找的,因为它只在你的应用程序运行时工作。UILocalNotification 让您创建一个由系统独立处理的通知(包括在特定时间安排它)。

于 2013-09-22T00:32:41.953 回答
1

NSTimer不能在后台无限运行。NSTimer当您的应用程序进入后台时暂停。

你必须使用repeatInterval属性UILocalNotification来实现它。

UILocalNotification *alarm = [[UILocalNotification alloc] init];
alarm.fireDate = [NSDate date];
alarm.timeZone = [NSTimeZone localTimeZone];
alarm.repeatInterval = NSMonthCalendarUnit;
[app scheduleLocalNotification:alarm];
于 2013-09-22T04:25:31.460 回答