1

我已经使用了此页面中苹果示例中的代码:Link,但我似乎无法让声音重复。我检查了其他应用程序,例如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];
        }
    }
}

关于如何解决这个问题的任何建议?

我曾建议将应用程序注册为音频播放器并在后台播放声音,但苹果似乎对这些应用程序很友好,因为它们不是真正的音频播放器。因此,他们否认这些应用程序。

问候,
保罗·皮伦

4

2 回答 2

4

对于本地通知,没有办法做到这一点。您可以注册为 VOIP 应用程序或“背景音频”应用程序,它们具有单独的 API。但是,如果您没有提供适当的功能来满足这些用途,您很可能会被拒绝。

于 2010-09-13T13:55:55.430 回答
0

是的,这是可能的,正如文档所述:

您自己的应用程序最多可以安排 128 个同时通知,其中任何一个都可以配置为以指定的时间间隔重复

您只需要配置repeatInterval属性:

重新安排通知的日历间隔。

于 2010-10-28T05:52:49.187 回答