首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iphone 4的后台应用程序

iphone 4的后台应用程序
EN

Stack Overflow用户
提问于 2010-09-08 18:15:57
回答 1查看 1.2K关注 0票数 0

我想让我的应用程序每隔20分钟播放一次声音,即使应用程序处于后台或iphone处于睡眠模式……我使用: NSTimer scheduledTimerWithTimeInterval:delay*60.0目标:自选择器:@选择器(GoMethod) userInfo:nil重复:是的;可能工作1小时然后停止可以有人帮助我解决这个问题……

EN

回答 1

Stack Overflow用户

发布于 2010-09-08 18:35:58

使用UILocalNotifications。

3个通知(即13:00、13:20和13:40),重复间隔:NSHourCalendarUnit.

编辑:如下所示:

代码语言:javascript
复制
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];
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3666668

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档