UILocalNotification
はiOS 10で廃止されているので、UNUserNotificationフレームワークを使用してローカル通知フローを更新しました。iOS 10 UserNotificationsカスタムサウンドはバックグラウンドモードで
アプリは、アプリがフォアグラウンドであり、それは正常に動作したときにAVPlayerを使用してカスタムサウンドを再生します。しかし、の背景モードでは、ローカル通知がトリガされたときに、カスタムサウンドの代わりに、デフォルト通知サウンドが再生されています。
しかし、 "didReceiveLocalNotification"メソッドを使用してiOS9で問題なく機能していたアプリは、バックグラウンドモードでもカスタムサウンドを再生できます。
アップデート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.")
}
})
私はすでに非常に多くの質問を経てきたが、解決策を取得できませんでした。
ご協力いただきますようお願い申し上げます。
はあなたがそれを固定してしまった – paper1111
を試してみましたが、コードを表示してくださいトリックをプロジェクトバンドル内に配置されたサウンドファイルをなかった設定...しかし、[この質問](のhttp:// stackoverflowの.com/questions/42495439/sound-issues-fix-for-ios-10-push-notifications)が近い将来に使用される可能性があります。 – Honey