ios - UNNotificationRequest 仅在 iPhone 解锁时播放自定义声音

标签 ios swift push-notification apple-push-notifications

我的应用正在下载一个 .wav 文件并将其移动到 Library/Sounds,然后使用该声音的文件名通过 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 中),但只有当我使用我的应用程序下载的声音并移至 Library/Sounds 时,我才会看到上述问题。

最佳答案

来自 here ,你会注意到:

Waveform Audio File Format (WAVE, or more commonly known as WAV due to its filename extension - both pronounced "wave"[6])3[7][8][9] (rarely, Audio for Windows)[10] is a Microsoft and IBM audio file format standard for storing an audio bitstream on PCs.

我假设 Apple 更喜欢原生 Apple 声音格式,例如 AIFFCAF ,两者均由 Apple 开发。

如果问题仍然存在,您可以使用 AIFF 或 CAF 声音文件格式重试并确认使用吗?

你也可以看看here .

关于ios - UNNotificationRequest 仅在 iPhone 解锁时播放自定义声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49020597/

相关文章:

ios - 我如何知道我的 iOS 应用程序崩溃了?

ios - 全屏模态视图 Controller 显示在表单下

ios - 使用 UIImagePickerController() 选择图像会自动旋转它们

ios - 类 "View controller"没有初始化程序

swift - Swift 中的委托(delegate)示例

ios - 根据条件导航到不同 View Controller 的按钮

android - PubNub GCM 推送通知未显示在通知栏中

IOS 没有收到 GCM 推送通知

android - 解析,推送通知。如何重置安装数据?

ios - 用户通知请求始终带有默认操作标识符