使用 CKSubscription / CKNotificationInfo 显示通知特定消息?
Show notification specific message with CKSubscription / CKNotificationInfo?
我想通知用户一条聊天消息已从其他用户发送,通知的正文应该是消息。是否可以用 CKSubscription
/ CKNotificationInfo
来设置?类似于 alertBody
,但特定于每条消息。知道怎么做吗?
let s2 = CKSubscription(recordType: recordType, predicate: NSPredicate(format: "destination = %@", CKReference(recordID: CKRecordID(recordName: loggedInUserSettingRecordName!), action: .DeleteSelf)), options: .FiresOnRecordCreation)
s2.notificationInfo = CKNotificationInfo()
s2.notificationInfo.alertBody = " "
s2.notificationInfo.soundName = UILocalNotificationDefaultSoundName
subscriptionsToSave.append(s2)
您可以像这样在警报中使用参数:
s2.notificationInfo.alertLocalizationKey = "Message from %1$@ : %2$@"
s2.notificationInfo.alertLocalizationArgs = ["FromName", "Text"]
由于这是一条本地化消息,您还需要将其添加到 Localizable.strings
"Message from %1$@ %2$@ : %1$@" = "Message from %1$@ %2$@ : %1$@";
我想通知用户一条聊天消息已从其他用户发送,通知的正文应该是消息。是否可以用 CKSubscription
/ CKNotificationInfo
来设置?类似于 alertBody
,但特定于每条消息。知道怎么做吗?
let s2 = CKSubscription(recordType: recordType, predicate: NSPredicate(format: "destination = %@", CKReference(recordID: CKRecordID(recordName: loggedInUserSettingRecordName!), action: .DeleteSelf)), options: .FiresOnRecordCreation)
s2.notificationInfo = CKNotificationInfo()
s2.notificationInfo.alertBody = " "
s2.notificationInfo.soundName = UILocalNotificationDefaultSoundName
subscriptionsToSave.append(s2)
您可以像这样在警报中使用参数:
s2.notificationInfo.alertLocalizationKey = "Message from %1$@ : %2$@"
s2.notificationInfo.alertLocalizationArgs = ["FromName", "Text"]
由于这是一条本地化消息,您还需要将其添加到 Localizable.strings
"Message from %1$@ %2$@ : %1$@" = "Message from %1$@ %2$@ : %1$@";