我正在使用uiNotificationService扩展成功地修改远程通知负载。
我想根据用户的选择更改警报声音。为此,我需要将uiNotificationsSound对象分配给bestAttemptContent:
bestAttemptContent.sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: "alertTone.caf"))
这将适用于我创建并导入到我的项目中的音调。在上面的例子中有一个名为alertTone.caf。
不过,我想使用系统提示音,而不是我自己的。我知道我可以设置默认音调,但我想访问其他自定义音调。有什么办法可以这么做吗?
最佳答案
您不能引用系统声音以获取未通知的声音,但当您在服务扩展中收到通知时,可以尝试播放该声音。
// 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的列表。