How to set sound from user ringtones in UILocalNotfication? - iphone

I want 10 ringtones, and as I am setting my UILocalNotification, I want the particular ringtone should be rang?
How can I do it?

You would need to add these ringtones as sound files to your project and then assign appropriate sound based on user selection. According to the documentation you can either specify the default sound using the constant or specify custom filename. No way to access iPhone's ringtones:
soundName The name of the file containing the sound to play when an
alert is displayed.
#property(nonatomic, copy) NSString *soundName
Discussion
For this
property, specify the filename (including extension) of a sound
resource in the application’s main bundle or
UILocalNotificationDefaultSoundName to request the default system
sound. When the system displays an alert for a local notification or
badges an application icon, it plays this sound. The default value is
nil (no sound). Sounds that last longer than 30 seconds are not
supported. If you specify a file with a sound that plays over 30
seconds, the default sound is played instead.

Related

How to choose Alarm tone from library?

I am new to iPhone Development.
i am trying to develop an Alarm application. I want to give a choice to the user to choose alarm ringtone from library like UIImagePickerController.
Is this possible ?
No, this is not possible, the UIImagePickerController is for image only and there is not such controller for picker the ringtone.
Also if you are scheduling alarms via UILocalNotification the the soundName property must contain a name of a sound file which is in you apps bundle.
For this property, specify the filename (including extension) of a sound resource in the application’s main bundle or UILocalNotificationDefaultSoundName to request the default system sound. When the system displays an alert for a local notification or badges an application icon, it plays this sound. The default value is nil (no sound). Sounds that last longer than 30 seconds are not supported. If you specify a file with a sound that plays over 30 seconds, the default sound is played instead.

Playing loop sound at certain time when iphone app is in background

I have a Clock Alarm app that plays sound at certain time (Sending local notifications). Is it possible to play loop sound at certain time (when local notification comes) when app is placed in background ?
Just want to specify: I need to play loop sound, not only once
No. The reason why is because you won't be able to execute any code because of a local notification. One thing you can do, and it's totally up to you if this is something your app really needs to di, it to list this application as an audio application on the UIBackgroundModes key of your .plist file, and just change song that is playing at the time it has to. You can use a dispatch_after block to change the song at the time you want it to.
Make your app a long running background app as described in this link here

How to change the notification sound of the iPhone using one coming from the iPod library

I have an alarm app in which I have a tableview where I am accessing all the iPod library songs. I want that when any of this song is selected this song must be set to the notification sound so when the alarm appears the alarm should ring with the sound selected from the iPod library.
ok I got your point. In my similar case i have achieved in following way, but that was somewhat different case. You can try one of the following case.
ONE CASE:
You can do one thing is You can store the URL of iPod Library song in NSUserDefault and pass that URL in didReceivedNotification method to your MPMediaPlayer class.
SECOND CASE
Another case will be copying the selected song in your app's document folder and then use that song for playing. For this you need to take care of previous files and delete them when selected new. This could make your app size somewhat larger.

how to set custom sound on local notification sound property

i am creating an alarm app by displaying local notification.i want to add custom sound to my local notification.i have added a sound #"crow.wav" to my resource folder and to my documents directory and in the notification.soundname property i have my filename like notification.soundname = #"crow.wav".But the problem is when the alarm rings the notification rings with the default sound .it does not ring with the sound that i have provided.What may be the problem.Please help me in solving this problem.Thanks.
Unfortunately it is not possible for us to set the soundName property as a name of audio file from other than main bundle i.e. if we want to assign the name of audio file from resources is possible .but at the same time if we try the same using file inside document directory apple wont allow you to do so . So please dont try it .U can refer apple docs for referance .try for another way for doing this ..plz .Reply
Information collected from iPhoneDocs:
1) Please Go through the documents and shaded part in it.
2)Scheduling Local Notifications
Configure the substance of the notification: alert, icon badge number, and sound.
• The alert has a property for the message (the alertBody property) and for the title of the action button or slider (alertAction); both of these string values can be internationalized for the user’s current language preference.
• You set the badge number to display on the application icon through the applicationIconBadgeNumber property.
• You can assign the filename of a nonlocalized custom sound in the application’s main bundle to the soundName property; to get the default system sound, OR assign UILocalNotificationDefaultSoundName. Sounds should always accompany an alert message or icon badging; they should not be played otherwise.

Sending a Value to an AVAudioPlayer Object to Play a Different Sound

I have an iphone app where I am playing a sound with one button using an AVAudioPlayer object. However, I would like to use a variable for the sound name and send a value to that variable. I have two other buttons that play different sounds and would like to send the sound name values to the variable that is in the AVAudioPlayer. How do I do that?
Thanks!
you can keep your audio files (in resource) with numeric names such as 1.mp3, 20.mp3, 41.wav etc and then you can use [NSString stringWithFormat:#"%d.mp3",soundId]; to generate sound file name to use generating absolute resource path and pass it to AVAudioPLayer
Best of Luck!!
This cannot be done. Create a new AVAudioPlayer for each new sound. If you wish to interrupt the current sound, send stop to the current instance.