我想让我的应用程序每隔20分钟播放一次声音,即使应用程序处于后台或iphone处于睡眠模式……我使用: NSTimer scheduledTimerWithTimeInterval:delay*60.0目标:自选择器:@选择器(GoMethod) userInfo:nil重复:是的;可能工作1小时然后停止可以有人帮助我解决这个问题……
发布于 2010-09-08 18:35:58
使用UILocalNotifications。
3个通知(即13:00、13:20和13:40),重复间隔: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];https://stackoverflow.com/questions/3666668
复制相似问题