gpt4 book ai didi

iOS推送通知自定义声音无法弄清楚

转载 作者:行者123 更新时间:2023-11-30 11:23:50 27 4
gpt4 key购买 nike

我的 AppDelegate 类中有一个 UNMutableNotificationContent 对象,设置如下:

let content = UNMutableNotificationContent()
content.title = "TITLE"
content.body = "Friendly message"
content.sound = UNNotificationSound.default()

在我的 Xcode 版本中,我有一个名为 Wake-up-sounds.wav 的自定义声音文件,我试图将 content.sound 设置为等于该声音文件,但我不知道如何设置。我该怎么做?

最佳答案

请尝试:

content.sound = UNNotificationSound.init(named: "Wake-up-sounds.wav")

苹果说:

To use the user’s preferred alert sound, use the default() method to create the sound object. To specify a custom sound, use the init(named:) method. Files for custom sounds must be located in your executable’s main bundle or in the Library/Sounds directory of your app’s container directory. Custom alert sounds are played by the system sound facility, so they must be in one of the following audio data formats: Linear PCM MA4 (IMA/ADPCM) µLaw aLaw You can package the audio data in an aiff, wav, or caf file. Sound files must be less than 30 seconds in length. If the sound file is longer than 30 seconds, the system plays the default sound instead

关于iOS推送通知自定义声音无法弄清楚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50974688/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com