How to set sound local notification from song in iTunes?

后端 未结 2 1247
春和景丽
春和景丽 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: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.

提交回复
热议问题