关于iPhone:闹钟iOS

Alarm Clock iOS

我正在开发"闹钟"应用程序。如何将选定的音频文件从设备传递到本地通知?

注意:我正在使用MPMediaPickerController从iPod音乐库中选择歌曲。


恐怕您无法通过推送通知播放iPod歌曲。

推送通知的sound属性引用应用程序捆绑包中的文件。也就是说,这是您的应用程序必须提供的文件(在捆绑包内,因此复制/下载到应用程序的Documents目录也不起作用)。另请参阅准备自定义警报声音。

此外,请注意要播放的声音长度较大:

Custom sounds must be under 30 seconds when played. If a custom sound is over that limit, the default system sound is played instead.


深色尘埃是正确的,您不能使用歌曲作为闹钟,您必须使用压缩声音.aif,.wav或文件格式,而声音必须具有压缩格式。

,并且您无法从库中进行设置,只能通过编程方式进行设置。基本上,警报与本地通知一起使用,因此您需要使用诸如此类的东西。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
    if (localNotif == nil)
        return;
    localNotif.fireDate = itemDate;
    localNotif.timeZone = [NSTimeZone defaultTimeZone];

    localNotif.alertBody = @"Please add reaction with your meal";
    // Set the action button
    localNotif.alertAction = @"View";


    localNotif.soundName = @"Iphone_Alarm.aif";
    //localNotif.soundName=@"sound.mp3";  // you cant use mp3 format
    localNotif.applicationIconBadgeNumber = 1;


    // Schedule the notification
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    [localNotif release];


无法将设备库中的歌曲分配给本地通知。
但是,您可以将其复制到应用程序的文档目录中,然后进行分配,最终,在触发通知或启动应用程序(您决定)时,如果不再需要该歌曲,则可以从应用程序文档中删除该歌曲。 >