私のアプリには公開CloudKitデータベースがあります。私はリモート購読のためにそれを使用しています。リモート通知のalertBodyでCKRecordのデータを表示する方法は?
私は、CloudKitダッシュボードにGlobalNotificationのレコードを作成し、このレコードのタイプString
のcontent
フィールドを作成したとの通知を動作させるために、私AppDelegateに次のメソッドを実装しました。その後
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let subscription = CKQuerySubscription(recordType: "GlobalNotification", predicate: NSPredicate(format: "TRUEPREDICATE"), options: .firesOnRecordCreation)
let info = CKNotificationInfo()
info.alertBody = "Some Text" // here i want to show content String data of a CKRecord which fired a notification
info.shouldBadge = true
info.soundName = "default"
subscription.notificationInfo = info
CKContainer.default().publicCloudDatabase.save(subscription, completionHandler: { subscription, error in
if error == nil {
// Subscription saved successfully
} else {
// An error occurred
}
})
}
私が作成新しいGlobalNotification
レコードをcloudKitダッシュボードに追加し、CloudKitダッシュボードのこのレコードのcontent
フィールドに「CloudKit content Text」を追加します。 デバイス上で通知が発生すると、alertBodyに「Some text」というテキストが表示されますが、「CloudKit content text」が表示されることがあります。
この通知で、GlobalNotification Recordのcontent
フィールドから取得した文字列を表示します。これを達成するためにコードをどのように変更する必要がありますか?
私はdesiredKeysについて読んで、info.desiredKeys = ["content"]を追加しようとしましたが、それは役に立たなかった。私もグーグルではありますが、解決策は見つけられていません。