我正在使用CloudKit中的推送通知。以下是我斯威夫特3之前使用:来自UNNotificationSound的声音名称
notification.soundName = UILocalNotificationDefaultSoundName
(通知是CKNotificationInfo
)
然而,这给了我一个警告:
'UILocalNotificationDefaultSoundName' was deprecated in iOS 10.0: Use UserNotifications Framework's +[UNNotificationSound defaultSound]
所以我加入了UserNotification框架,以我的Xcode项目,我将它导入到我的ViewController。那么我想这:
notification.soundName = UNNotificationSound.default()
然而,这给了我一个错误:
Cannot assign value of type 'UNNotificationSound' to type 'String?'
所以默认的声音是UNNotificationSound
,但我需要的声音名称。我怎样才能从声音中获得声音名称?谢谢!
这不是我正在寻找的东西...我不相信我需要'UNNotificationRequest'。另外,content.sound不幸的是只能得到。 – penatheboss
.sound对于UNNotificationContent只能获取,但如果使用UNMutableNotificationContent,则可以将其设置为您要使用的声音。 – gohnjanotis