how to set custom sound on local notification sound property - iphone

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.

Related

How to set current playback duration and elapsed time on iOS 7 lockscreen?

Starting from iOS 5, every music player can set current playing music information such as title, artist, album title, and artwork on [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo to show on lock screen.
On iOS 7, playback position slider, duration, and elapsed time information are added to both lock screen and control center. However, I cannot find any documents to set these kinds of information and enable the slider to change playback position.
Is there any way to solve this problem?
You need to setup playback rate to 1.0f even if documentation says it's 1.0 by default.
NSDictionary *mediaInfo = #{
MPMediaItemPropertyTitle: audio.title,
MPMediaItemPropertyArtist: audio.artist,
MPMediaItemPropertyPlaybackDuration: audio.duration,
MPNowPlayingInfoPropertyPlaybackRate: #(1.0)
};
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:mediaInfo];
They're all documented in the reference for MPNowPlayingInfoCenter. The currently playing properties are optional values that may or may not be set. The link to that is in the sentence at the end of the list of normal playing properties:
Additional properties you can set are described in this document in “Additional Metadata Properties.”. (emphasis mine)
The properties that you are interested in are: MPNowPlayingInfoPropertyElapsedPlaybackTime and MPMediaItemPropertyPlaybackDuration.
This information is all publicly available, and as the iOS 7 SDK does not seem to be published yet (as of 2013-09-14), I presume it was available prior to that version of iOS as well.
Just be warned: Apple's document never made this clear -- If you use MPMusicPlayerController, your music is played under the hood by the "music" app and you do NOT have any control of nowPlayingInfoCenter. And you will NOT receive remote control events generated by the user actions (such as play/pause) applied to the lock screen because those events are propagated via the nowPlayingInfoCenter to the "music" app, not to yours. When using other media players, such as AV or AvAudio, you can control the nowPlayingInfoCenter and receive the remote control events. But if you use AVAudioSessionCategoryOptions.MixWithOthers to set up the AV player, you can't control nowPlayingInfoCenter either. I wish Apple documented those details better.

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.

Building a background app with audio and location services

I'm building an app that is location-aware and triggers text to speech whenever the user gets near a certain point. I have singleton classes GPSManager (for getting location updates) and RouteDetails (for defining the points that should trigger the text-to-speech). I also have a view controller that shows a map updating the user's location from GPSManager and showing a route from RouteDetails.
What I want to do is keep the functionality of the view controller running when the app is suspended, i.e. be notified when the location is updated, compare it to the locations in RouteDetails, and then play the text-to-speech. However I can't seem to find a good example of this being done - how do I made sure RouteDetails and GPSManager stay in memory? And where should I put the text-to-speech module where it can access the details in RouteDetails and also be in memory so that it can play when the app is suspended and the phone is locked? I'm assuming the view controller can't receive notifications when the app is suspended.
Also, I've added the location and audio options to the UIBackgroundModes key in the Info.plist file. And I don't need the app to bring itself back into the foreground when it gets a location update/plays a sound, it just needs to play a sound and update a variable in RouteDetails.

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 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.