我正在使用 UINotificationServiceExtension 成功修改我的远程通知负载。
我想根据用户在这里的选择更改提示音。为此,我需要将 UINotificationSound 对象分配给 bestAttemptContent:
bestAttemptContent.sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: "alertTone.caf"))
这适用于我创建并导入到我的项目中的音调。上例中的一个名为 alertTone.caf。
但是,我想使用系统提示音而不是我自己的提示音。我知道我可以设置默认音调,但我想访问其他自定义音调。有没有办法做到这一点?
最佳答案
UNNotificationSound 不能引用系统声音,但可以尝试在服务扩展中收到通知时播放声音。
// import
import AVFoundation
// create a sound ID, in this case its the tweet sound.
let systemSoundID: SystemSoundID = 1016
// Play the correct sound when the notification is received in the service extension
AudioServicesPlaySystemSound (systemSoundID)
播放系统声音的来源here .
This是您可以用作引用的所有系统声音 ID 的列表。
关于ios - 在 UNNotificationServiceExtension 中为 iOS 远程通知添加系统声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57913791/