I am building an application in which I have to include an Alarm. In this scenario, I am not getting on which frame should I rely on. Adding, I need to play default audio file as recorded one. How can I play default audio files?? Please help me in this regard..
Thanks in advance.
What you want is a local sound notification. You can go through this tutorial.
Also note that you can not use any sounds not provided within your application. Here is a extract from the docs:
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.
Related
I implemented local notification in my app but I am just wondering is there a way to play a sound that is not part of the NSMainbundle.Basically in my app, I want user to record a sound that gets played when the local notification is generated instead of playing a pre-recorded sound. I have read out the Apple Documentation but i have also seen 2 -3 Apps on app store which is doing it like the this App link of the App i am wondering how the are playing custom sounds (sounds which are not the part of NSMainBundel)
Anyone has any idea how I can do it ?
Thank you in Advance
What you can do is to utilize the AVAudioRecorder and save its recordings to the documents directory of the iPhone.
After the recording is done, you can play the very same files using an AVAudioPlayer via the path of the recorded files.
HTH
Within my iOS application, how can I play a sound file stored in the application's documents directory for a local notification, rather than one inside the application bundle?
I've seen a couple of applications on the App Store do this, and I was wondering how this is possible.
It is actually possible to play a custom sound in a local notification that isn't in the app's main bundle (NSBundle).
The sound has to be stored in the Library/Sounds directory, for example:
/var/mobile/Containers/Data/Application/DD7E6BA0-2FC0-4DE0-95BF-C2E9C9A94E08/Library/Sounds/mySound.caf
When you reference the sound file in the UILocalNotification soundName property, you simply write the filename, rather than the full directory path:
alert.soundName = #"mySound.caf";
Tested and working on iOS9.3.5. I haven't tried on other iOS versions yet.
Footnote:
I happened to find this information when searching the Apple Documentation regarding Remote Notifications Here - Specifically, the 'Payload Keys' section, where it mentions sound.
Apple's documentation for Local & Remote Notifications (Here) also mentions that the sound files can be utilised if they are in the app's main bundle OR the data container:
To play a sound, assign a sound to the soundName property. You can assign the filename of a nonlocalized custom sound in the app’s main bundle (or data container) or you can assign UILocalNotificationDefaultSoundName to get the default system sound. A sound should always accompany the display of an alert message or the badging of an icon; a sound should not be played in the absence of other notification types.
No you can not play an audio file that is not in the bundle and you can not modify the application bundle at runtime. One reason why Apple requires all sounds for local notifications to be bundled with the application may be for security reasons, that would make it possible for all bundled files to be checked for security risks during the review process.
Exactly .....
You can not play audio file stored in document directory for alarm as a local push notification.
I also had gone through various apps on app store .those apps basically look like playing customise audio from document directory for local push notification but it is not .insted it using push notification and when notification come at that time when we click on view button of that notification the app which generated the local push notification will get invoked and finally the selected audio file get played .
In this way the app is look like customized push notification using customized audio file from document directory
So my application for iphone4 reads data from the accelerometer and sends it to another application via tcp sockets. I need my app to work in background mode, so what I did was:
I put an mp3 file in the application's Documents folder
I used AVAudioPlayer library to play the file in a loop. It works.
I edited Info.plist and added option "required background
modes" with "audio" on.
Still, the scheduler suspends the application whenever I press the iphone's home button. Is there anything I missed?
I read apple's documentation, but I didn't find a solution. A few thoughts on this:
do I have to edit appDelegate.m?
is it because I use AVAudioPlayer instead of the iPod?
is it because I play an audio file from the application documents
folder?
I read about one person changing iOS Development Target from 4.0 to
3.2.1, but that didn't work for me.
And finally, say I get this to work, would the application still be getting data from the accelerometer?
On a side note, I don't want to submit the application to the App Store.
No, you will not receive accelerometer notifications in background mode. As far as I know, it is not possible. Check Executing Code in Background.
If you read the docs carefully, you will know that the whole background code model is based on responding to specific events (location and voip modes).
As for the audio mode here is an extract from Apple:
Your application should limit itself to doing only the work necessary
to provide data for playback while in the background. For example, a
streaming audio application would download any new data from its
server and push the current audio samples out for playback. You should
not perform any extraneous tasks that are unrelated to playing the
content.
Not sure whether you have solved your issue or not since this question was posted more than one year ago. Also, not sure whether playing audio is a must in your app or not. If both answers are no, my recent investigation may help a bit.
Here are how I get my app getting accelerometer data at the background
1. Follow this tutorial http://mobile.tutsplus.com/tutorials/iphone/ios-multitasking-background-location/ to get the background location working.
2. Follow this tutorial http://jonathanhui.com/ios-motion to get the accelerometer working.
Then you can get an app collecting accelerometer data at the background. Hope this helps.
I have implemented Push Notification and have been using Default sounds every time. I know that there are many other sounds as well that I can use but I don't know the names of all sounds that Apple support for Push Notification. Can someone please help me to get the list?
Thanks.
You could put your own sound file , which you like to play.
From apple documentation.
You can package the audio data in an
aiff, wav, or caf file. Then, in
Xcode, add the sound file to your
project as a nonlocalized resource of
the application bundle.
See more
The sound has to be bundled with your app.
You can use any sound you desire (and you have the rights to) - but you need to correctly encode the sound to work on the device (caf, aiff, wav). You must embed the sound as a resource within your project bundle, you cannot use "Any sound" on the device. Once embedded, you can reference it by filename in your payload for the sound.
Caveat - your sound must be under 30 seconds long and there is no mechanism to loop the sound)
Apple Push Documentation
I have used Local Notification in my app an successfully generated an alert at correct time..
But when i tried following code for playing sound it does not play....
localNot.soundName =#"Ghulam Ali-Chamkte Chaad Ko.mp3";
Can anyone tell me the reason....Does the playing length of sound file affects
According to the Apple Developer Documentation, you need to use "aiff", "caf" or "wav" files.
The link provided shows some ways of converting audio to these formats on your mac.