UILocalNotification重复声音

发布于 2024-09-17 20:55:45 字数 1740 浏览 4 评论 0 原文

我使用了此页面中苹果示例的代码: 链接,但我似乎无法让声音重复。我检查了其他应用程序,例如 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枕梦 2024-09-24 20:55:45

对于本地通知,无法执行此操作。您可以注册为 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.

女中豪杰 2024-09-24 20:55:45

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

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

您只需配置 repeatInterval 属性:

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

Yes this is possible, as the documentation states:

Your own applications can schedule up to 128 simultaneous notifications, any of which can be configured to repeat at a specified interval

You just need to configure the repeatInterval property:

The calendar interval at which to reschedule the notification.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文