[英]custom sound not working in unnotificationrequest ios 10 objC
[英]UNNotificationRequest plays custom sound only when iPhone is unlocked
我的應用程序正在下載.wav文件並將其移至“庫/聲音”,然后通過UNNotificationRequest
具有該聲音文件名的本地通知。 此請求將按預期發送通知,但是我添加的自定義聲音僅在手機解鎖時大聲播放,而不是在通知傳遞到手機的鎖定屏幕時才大聲播放。 但是,如果我使用UNNotificationSound.default()
而不是自定義聲音,則默認的推送聲音將同時在鎖定屏幕和解鎖設備時播放。 任何人都有什么想法可能導致此問題? 我的代碼很簡單:
let soundName = "demoSound.wav" // (or nil to use default)
let center = UNUserNotificationCenter.current()
center.removeAllPendingNotificationRequests()
let content = UNMutableNotificationContent()
content.title = "Title"
content.body = "Body";
content.sound = soundName.flatMap { UNNotificationSound(named: $0) } ?? UNNotificationSound.default()
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60, repeats: true)
let identifier = "PushNotifierLocalNotification"
let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)
center.add(request, withCompletionHandler: nil)
編輯:這對於捆綁的聲音(拖放到Xcode中)不是問題,但是只有當我使用由我的應用下載並移至“庫/聲音”中的聲音時,我才看到上述問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.