How to set sound local notification from song in iTunes?

后端 未结 2 1248
春和景丽
春和景丽 2021-02-09 09:51

I try to create alarm app but I don\'t know how to set song from iTunes to sound of local notification.

Now I use this code to call iTunes

- (void)tabl         


        
相关标签:
2条回答
  • 2021-02-09 10:18

    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.

    0 讨论(0)
  • 2021-02-09 10:24

    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.

    0 讨论(0)
提交回复
热议问题