iOS、Swift、CloudKitを使用してメッセージングアプリケーションを作成しようとしています。私は正常にそれを作った、誰かが別のメッセージを追加するたびにプッシュ通知を送った。しかし、プッシュ通知のテキストがメッセージに何があったのかを伝えたいと思います。通知を送信するためのCloudKitサブスクリプションのアップデート方法
デフォルトのコードを:ここに私が試したものである
let subscription = CKSubscription(recordType: "Responses", predicate: NSPredicate(format: "TRUEPREDICATE", argumentArray: nil), options: .FiresOnRecordCreation)
let notification = CKNotificationInfo()
notification.alertBody = "New Message Sent"
notification.soundName = UILocalNotificationDefaultSoundName
subscription.notificationInfo = notification
CKContainer.defaultContainer().publicCloudDatabase.saveSubscription(subscription) { (result, error) -> Void in
if error != nil {
print(error!.localizedDescription)
}
}
これは私が「送信新規メッセージを」と言い、各メッセージの通知を送信することができます。
//publicDB is the CKContainer.defaultContainer.publicDatabase
publicDB.fetchAllSubscriptionsWithCompletionHandler({ (subscriptions, error) in
if error != nil {
self.displayError(self.getStringFromError(error!))
} else {
for subscription in subscriptions! {
subscription.notificationInfo?.alertBody = self.responseTextField.text
}
}
})
let record = CKRecord(recordType: "Responses")
record.setObject(currentUsername, forKey: "respondedBy")
record.setObject(responseTextField.text, forKey: "response")
publicDB.saveRecord(record) { (record, error) in
//code for updating tables, etc.
//Notification on other device sent
}
は、サブスクリプションのalertBody
(私は上記の実行しようとしました何を)動作しないの設定:これは私が指定した通知のためにしようとしているものです。サブスクリプションのalertBodyを更新するための他のソリューションはありますか?ありがとう!
私は申し訳ありませんを参照、私はあなたのコードがどのように動作するか理解していません。だから私はそれらのプロパティを通知情報に追加した後、どうすればいいですか?また、Localization.Stringとは何ですか?助けてくれてありがとう – penatheboss
答えを更新しました...しかし、クラウドキットに基づいたメッセージングアプリを作っているのであれば、見てみるべきです。https://github.com/evermeer/EVCloudKitDao –
Ok。私は今日の午後に、チャンスを得るときにコードを試してみます。私はそれがどのように進むのかを知らせます。期待しているようだ! – penatheboss