How to set sound local notification from song in iTunes?

帅比萌擦擦* 提交于 2019-12-03 07:13:17

You can only use sounds that are a part of the main bundle, meaning, they have be in the build of the app when submitted to the app store.

Yes, you can record sound, download sound, etc in app, but none of those sounds files created/saved can be used, because they are not in the app's bundle. If an app is using custom sounds by accessing them outside of the bundle, then they are using private APIs to do so. Trust me, I've tried every option I can think of.

As noted by @thephatp, a notification (local or remote) can only trigger playback of sounds that are in the app bundle. I see no way around this.

@r3dsm0k3 asks in his comment how apps like Rise trigger playback of sounds that aren't in the app bundle. If I had to guess, I would say that Rise registers itself as an app requiring the audio background mode:

Declaring Your App’s Supported Background Tasks

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

This effectively means that Rise is allowed to stay running all the time. It's allowed to do so because it plays audio on behalf of the user. That it doesn't play audio 100% of the time doesn't appear to be a problem for Apple.

Rise may or may not use UILocalNotifications. Most likely they only use these as a backup incase the app DOES get unloaded, and instead use another timer mechanism to trigger the wakeup alarm sequence.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!