I have an app that requires that the user record their own message to be played back at some future time. My intent was to do that using UILocalNotification. Unfortunately, it seems that the sound associated with the local notif has to be stored in the main bundle but the user cannot make a recording and save it in the bundle.
How do I get a user recorded sound file to be played via local notification?
Alternatively - is there a way if the app is not running to capture the local notification (without waiting for the user to respond to an alert) and then play the desired soundfile?
Thanks!
The local notification's
soundname
property can refer to the path of a sound file within the app's bundle. A sound recording of the user's voice cannot be used as it cannot be saved to the app bundle at runtime.You cannot have a default notification show up and then open the app and play the recorded voice, unless the user has tapped on the notification. Which means, if the user is not using the phone, the only chance that they will listen to the recording is if they pick up the phone, unlock it, and tap on the notification. So I believe that this is far from what you want.
I think this is possible for ios 9, this is what apple documentation says:
I tested saving a sound into the Library/Sounds folder then using it with a local notification and it worked fine on iOS 9, after that I tried the same on iOS 8 and it didn't work, so my conclussion was that this is possible for iOS 9 only
You can access the library directory in this way:
You have to create the directory if it doesn't exist:
and you can then save your sounds there.
You can assign a (custom) sound to a
UILocalNotification
by setting its property as follows:Unfortunately, according to the reference, it is not possible to use a sound file that is not stored in the main bundle or is declared by apple:
See also UILocalNotification Class Reference #soundName