How to choose Alarm tone from library? - iphone

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.

Related

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

Assign alert tone for UILocalNotification from available sounds in iphone

I am working on an app that used UILocalNotification. I wanted to select sound from default sounds that came with iPhone. How can i list down sounds for assign as the alert tone.
There is one standard sound for notification from system (UILocalNotificationDefaultSoundName). You can play any custom sound shorter than 30 seconds. So, if you can download any native sound from ios from anywhere, you will be able to use it as custom sound. Documentation

Responding to events when device has been locked

I'm working on a radio alarm clock, and i have some issues.
I am using local notifications for the alarms, so it has a gentle fallback if the app is not running.
I am well aware of the limitations of the device, and i know what i can and cannot do when the device has gone into background.
But my question is this:
I have seen other apps starting an audio streamer when i've locked the device. How is this possible? May this be inside an execution-timeframe?
How is the best way to implement this? Is it any way i can activate a streaming session when the device is locked?
Edit
To clarify: I know how i make audio play in the background. But the issue is triggering the audio-playback when an local notification or some other event fires.
One app that seems to do this, is Radio Alarm Clock. I haven't tried it for long period of times yet. But it seems to do this. A video demo of the app: http://www.youtube.com/watch?v=KJQiFOcdBWk
Have you already declared your background task?
Support for some types of background execution must be declared in advance by the app that uses them. An app declares support for a service using its Info.plist file. Add the UIBackgroundModes key to your Info.plist file and set its value to an array containing one or more of the following strings:
audio — The app plays audible content to the user while in the background. (This content includes streaming audio or video content using AirPlay.)
iOS App Programming Guide - Implementing Long Running Background Tasks
You can add this by clicking on your main project icon, then under the Info tab you can add "Required Background Modes" to the "Custom iOS Target Properties" section. "App Plays Audio" will be one of the three default values.
Big Edit With New Answer:
If everything else is already in order, you can keep your app running in the background using the UIApplication method
- (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler:(void (^)(void))handler
detailed here: UIApplication Class Reference
with an example here: Hour 21: Building Background-Aware Applications
This allows you to run an instance of NSTimer which triggers your music player. The difference between this approach and UILocalNotifications is that this method never lets the app fully enter the background mode, the music player exists the entire time which subverts the need to create it from the background, which looks to be impossible.
There may be limitations to how long of a timer you can set, I haven't tested this past 14 minutes out.

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.

How to set sound from user ringtones in UILocalNotfication?

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.