我想让我的应用程序每 20 分钟播放一次声音,即使应用程序处于后台或 iphone 处于 sleep 模式...我使用:[NSTimer scheduledTimerWithTimeInterval:delay*60.0 target:self selector:@selector(goMethod) userInfo:零重复:是];可能工作 1 小时然后停止,任何人都可以帮助我解决这个问题......
最佳答案
使用 UILocalNotifications。
3 个通知(即 13:00、13:20 和 13:40)与 repeatinterval:NSHourCalendarUnit..
编辑:
像这样的东西:
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.repeatInterval = NSHourCalendarUnit; //Repeat every hour
localNotif.fireDate = [NSDate date]; //Now
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
localNotif.fireDate = [NSDate dateWithTimeIntervalSinceNow:1200]; //Now + 20 min
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
localNotif.fireDate = [NSDate dateWithTimeIntervalSinceNow:2400]; //Now + 40 min
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
关于iphone - iphone 4的后台应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3666668/