闹钟 iOS

发布于 2024-11-06 02:23:34 字数 96 浏览 4 评论 0 原文

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

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

I am developing an application of Alarm Clock. How can I pass the selected audio file from the device to the local notification ?

Note : I am using MPMediaPickerController to pick the song from iPod Music Library.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

请爱~陌生人 2024-11-13 02:23:34

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

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

另请注意,要播放的声音有一个上限:

自定义声音播放时长必须低于 30 秒。如果自定义声音超过该限制,则会播放默认系统声音。

I'm afraid you can't play an iPod song with a push notification.

The sound property of a push notification references a file within your application bundle. That is, it's a file that your app must provide (inside your bundle, so copying/downloading into your app's Documents directory doesn't work either). See also Preparing Custom Alert Sounds.

Also, note that there is an upper length of the sound to be played:

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

嘴硬脾气大 2024-11-13 02:23:34

暗尘是对的,您不能使用歌曲作为闹钟,您必须使用压缩声音 .aif、.wav 或具有压缩格式声音的文件格式。

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

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];

Dark dust is right you cant use a song for your alarm you must need to use a compress sound .aif, .wav or file format which having sound in compressed format.

and you cant set from a library you can set only by programatically. Basically alarm is used with local notification so you need to use some thing like this.

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];
烟燃烟灭 2024-11-13 02:23:34

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

It's not possible to assign a song from the device library to the local notification.
However, you can copy it in you app's Documents Directory and then assign it, and eventually, when the notification is fired or app is launching (you decide) you can delete that song from the app Documents if it is not needed anymore.

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