开发者

Alarm Clock iOS

I am developing an开发者_JS百科 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.


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜