UNNotificationSound 不起作用

Ada*_*aka 2 audio notifications ios10

新的 iOS10 用户通知框架的自定义声音不起作用。相同的文件适用于旧的 UILocalNotification,但现在总是播放默认系统声音。当我设置 nil 时,我没有声音,所以只有名字的 init 是有问题的

let notificationContent = UNMutableNotificationContent()
notificationContent.title = "XYZ"
notificationContent.body = "XYZ"
notificationContent.sound = UNNotificationSound(named: "sound_name.aif")
Run Code Online (Sandbox Code Playgroud)

Sko*_*vie 5

我改变了这一行:

notificationContent.sound = UNNotificationSound(named: "sound_name.aiff")
Run Code Online (Sandbox Code Playgroud)

到 :

notificationContent.sound = UNNotificationSound.init(named: "sound_name.aiff")
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,我将我的声音转换为*.aiff 在阅读 API 参考后,我将我的声音文件移动到一个名为 Sounds 的文件夹中。

我确保我的声音文件在 30 秒以内