由于iOS 10中
当应用程序在前台时,使用AVPlayer播放自定义声音,这很好用。但是在后台模式下触发本地通知时,播放的是默认通知声音而不是自定义声音。
然而,在iOS9中一切都正常,使用"didReceiveLocalNotification"方法,即使在后台模式下,应用程序也可以播放自定义声音。
更新1:
我正在按以下方式设置本地通知:
UILocalNotification
已经被弃用,因此我使用UNUserNotification框架更新了本地通知流程。当应用程序在前台时,使用AVPlayer播放自定义声音,这很好用。但是在后台模式下触发本地通知时,播放的是默认通知声音而不是自定义声音。
然而,在iOS9中一切都正常,使用"didReceiveLocalNotification"方法,即使在后台模式下,应用程序也可以播放自定义声音。
更新1:
我正在按以下方式设置本地通知:
let content = UNMutableNotificationContent()
content.title = NSString.localizedUserNotificationStringForKey("reminder!", arguments: nil)
content.body = NSString.localizedUserNotificationStringForKey("Reminder body.", arguments: nil)
if let audioUrl == nil {
content.sound = UNNotificationSound.defaultSound()
} else {
let alertSound = NSURL(fileURLWithPath: self.selectedAudioFilePath)
content.sound = UNNotificationSound(named: alertSound.lastPathComponent!)
}
content.userInfo = infoDic as [NSObject : AnyObject]
content.badge = 1
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60, repeats: false)
let identifier = "Reminder-\(date)"
let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)
let center = UNUserNotificationCenter.currentNotificationCenter()
center.addNotificationRequest(request, withCompletionHandler: { (error) in
if error != nil {
print("local notification created successfully.")
}
})
我已经查看了许多SO问题,但没有找到解决方案。
非常感激任何帮助!