我正在尝试在一天中的特定时间执行某项操作。
我不想使用 UILocalNotification
因为我不希望用户在发生任何事情时离开。
我当前的代码是:
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(fire:) userInfo:nil repeats:NO];
最佳答案
你可以:
每次您的应用在
application:didFinishLaunchingWithOptions
方法中使用[NSDate date]
时提取当前本地时间。使用
dateWithTimeInterval:sinceDate
计算您的闹钟的剩余时间。使用
interval = that_time_difference
启动一个NSTimer
。
我不知道你说的是什么意思:
"I don't want the users to be away of anything happening."
我假设您不希望应用程序未运行时发生任何事情。我唯一能想到的就是推送通知。
关于ios - 如何使用 NSTimer 在特定时间执行操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15329496/