Start playing sound in background on iOS?

后端 未结 2 1775
渐次进展
渐次进展 2021-01-02 21:29

I\'m trying to do something similar to Tile.app. When it shows a notification, it plays a sound. That seems simple enough-- use UILocalNotification and include

2条回答
  •  失恋的感觉
    2021-01-02 21:34

    From official Apple documentation:

    "Custom sounds must be under 30 seconds when played. If a custom sound is over that limit, the default system sound is played instead."

    There is no way that you can make UILocalNotication to loop the sound. You can schedule it again with time intervals for 30s, but that one will be a schedulation of another alarm.

    To setup your custom notification sound:

    notif.soundName = @"sound.caf";
    

    Make sure the sound is actually in your app’s bundle, is in the correct format (linear PCM or IMA4—pretty much anywhere that explains how to convert sounds for iOS will tell you how to do that), and is under 30 seconds.

提交回复
热议问题