我正在使用 CloudKit 中的推送通知。这是我在 Swift 3 之前使用的:
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
,但我需要声音名称。如何从声音中获取声音名称?谢谢!
最佳答案
使用新的 UserNotifications
框架:
import UserNotifications
let content = UNMutableNotificationContent()
content.sound = UNNotificationSound.default()
let request = UNNotificationRequest(identifier: "id", content: content, trigger: nil)
关于ios - 来自 UNNotificationSound 的声音名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38674237/