新しい UNNotificationContentExtension を使用して、ローカル通知用のカスタム ユーザー インターフェイスを表示しようとしていますが、デフォルトの通知アラートしか表示されません。
Xcode テンプレートで拡張機能を作成UNNotificationExtensionCategory
し、Info.plist で指定しました。
この後、通知の登録と設定を行っていUNNotificationCategory
ますapplication(_:didFinishLaunchingWithOptions:)
let center = UNUserNotificationCenter.current()
center.requestAuthorization([.alert, .sound]) { (granted, error) in
// Enable or disable features based on authorization.
}
let action = UNNotificationAction(identifier: "Delete", title: "Delete", options: [])
let category = UNNotificationCategory(identifier: "notify-test", actions: [action], minimalActions: [], intentIdentifiers: [], options: [])
UNUserNotificationCenter.current().setNotificationCategories([category])
アプリが次のコードでバックグラウンドに入ってから 5 秒後にトリガーするように通知をスケジュールしています。
let content = UNMutableNotificationContent()
content.title = NSString.localizedUserNotificationString(forKey: "Hello!", arguments: nil)
content.body = NSString.localizedUserNotificationString(forKey: "Hello_message_body", arguments: nil)
content.sound = UNNotificationSound.default()
content.categoryIdentifier = "notify-test"
let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 5, repeats: false)
let request = UNNotificationRequest.init(identifier: "notify-test", content: content, trigger: trigger)
let center = UNUserNotificationCenter.current()
center.add(request)
通知は期待どおりに発生しますが、iOS では既定のスタイルが表示され、既定のストーリーボード ファイルで定義されたカスタム UI は表示されません。誰かが以前に同じ問題に遭遇し、ここで私を助けることができるかもしれません.