iphone - iphone 4的后台应用

标签 iphone xcode audio background

我想让我的应用程序每 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/

相关文章:

ios - 将静态时间转换为 NSDate 返回旧日期

ios - NSPredicate 'The left hand side for an ALL or ANY operator must be either an NSArray or NSSet'

iphone - 在 ViewDidAppear 中创建 TableView

ios - Cordova IOS 构建错误(清理项目)

ios - 将 MFSideMenu 3rd 方库添加到 swift 项目

java - 顺畅的声音搜寻

android - 4,5秒后流音乐中断

javascript - 悬停时播放音频文件(并在鼠标移开时停止播放)

iphone - 向 UITableView 添加附件

iphone - 如何以编程方式将 UIToolbar 添加到 UITableViewController?