UILocalNotification重复声音
我使用了此页面中苹果示例的代码: 链接,但我似乎无法让声音重复。我检查了其他应用程序,例如 Skype(用于 VOIP)和 Alarm Clock Pro(音频?),但我无法重复播放声音文件。
这是我的代码:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
AlarmHandler *AHinstance = getAlarmHandlerInstance();
UIApplication* app = [UIApplication sharedApplication];
NSArray *alarmList = [AHinstance getAlarms];
NSArray *oldNotifications = [app scheduledLocalNotifications];
if ([oldNotifications count] > 0)
{
[app cancelAllLocalNotifications];
}
for (Alarm *theAlarm in alarmList) {
NSDate *alarmDate = [theAlarm getNearestActivationDate];
Package *alarmPackage = [theAlarm getAlarmPackage];
NSArray *fileList = [alarmPackage getVoiceFileListForBackgroundNotificationWithHour:theAlarm.larmHour];
if( alarmDate == nil ) continue;
UILocalNotification* alarm = [[[UILocalNotification alloc] init] autorelease];
if (alarm)
{
NSLog(@"File: %@", [fileList objectAtIndex:0]);
alarm.fireDate = alarmDate;
alarm.timeZone = [NSTimeZone defaultTimeZone];
alarm.soundName = [fileList objectAtIndex:0];
alarm.alertBody = @"Time to wake up!";
alarm.repeatInterval = 0;
[app scheduleLocalNotification:alarm];
}
}
}
关于如何解决这个问题有什么建议吗?
我曾建议将应用程序注册为音频播放器并在后台播放声音,但苹果似乎确实对这些应用程序很友好,因为它们不是真正的音频播放器。因此他们拒绝这些应用程序。
问候,
保罗·皮伦
I have used the code from apples example from this page: Link, but I can't seem to get the sound to repeat. I have checked other applications, such as skype (for VOIP) and Alarm Clock Pro (audio?) but I cannot get the sound file to be repeated.
This is my code:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
AlarmHandler *AHinstance = getAlarmHandlerInstance();
UIApplication* app = [UIApplication sharedApplication];
NSArray *alarmList = [AHinstance getAlarms];
NSArray *oldNotifications = [app scheduledLocalNotifications];
if ([oldNotifications count] > 0)
{
[app cancelAllLocalNotifications];
}
for (Alarm *theAlarm in alarmList) {
NSDate *alarmDate = [theAlarm getNearestActivationDate];
Package *alarmPackage = [theAlarm getAlarmPackage];
NSArray *fileList = [alarmPackage getVoiceFileListForBackgroundNotificationWithHour:theAlarm.larmHour];
if( alarmDate == nil ) continue;
UILocalNotification* alarm = [[[UILocalNotification alloc] init] autorelease];
if (alarm)
{
NSLog(@"File: %@", [fileList objectAtIndex:0]);
alarm.fireDate = alarmDate;
alarm.timeZone = [NSTimeZone defaultTimeZone];
alarm.soundName = [fileList objectAtIndex:0];
alarm.alertBody = @"Time to wake up!";
alarm.repeatInterval = 0;
[app scheduleLocalNotification:alarm];
}
}
}
Any suggestions on how I can fix this?
I have had suggestions to register app as audio player and play sounds in the background, but it seems that apple does take kindly to those applications because they aren't real audio players. Therefore they deny those apps.
Regards,
Paul Peelen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于本地通知,无法执行此操作。您可以注册为 VOIP 应用程序或“背景音频”应用程序,它们具有单独的 API。但是,如果您没有提供适当的功能来满足这些用途,您很可能会被拒绝。
There is no way to do this for local notifications. You can either register as a VOIP app or as a "background audio" app, which have separate APIs. However, if you do not provide appropriate functionality to qualify for those kinds of uses, you'll most likely be rejected.
是的,这是可能的,正如文档所述:
您只需配置 repeatInterval 属性:
Yes this is possible, as the documentation states:
You just need to configure the repeatInterval property: