簡體   English   中英

僅當iPhone解鎖時,UNNotificationRequest才會播放自定義聲音

[英]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中)不是問題,但是只有當我使用由我的應用下載並移至“庫/聲音”中的聲音時,我才看到上述問題。

這里 ,您會注意到:

波形音頻文件格式(WAVE,或更常稱為WAV由於其文件擴展名-既發音為“波”[6]) 3 [7] [8] [9](很少,音頻用於Windows)[10] 是一個Microsoft和IBM音頻文件格式標准,用於在PC上存儲音頻比特流。

我以為Apple偏愛Apple原生的聲音格式,例如AIFFCAF ,它們都是由Apple開發的。

如果問題仍然存在,您可以重試AIFF或CAF聲音文件格式並確認使用嗎?

您也可以在這里看看。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM