使用CKSubscription / CKNotificationInfo显示通知特定消息?

时间:2015-08-16 10:20:33

标签: ios cloudkit

我想通知用户已从其他用户发送了聊天消息,并且通知正文应该是消息。这是用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)

1 个答案:

答案 0 :(得分:1)

您可以在警报中使用如下参数:

s2.notificationInfo.alertLocalizationKey = "Message from %1$@ : %2$@"
s2.notificationInfo.alertLocalizationArgs = ["FromName", "Text"]

由于这是一个lokalized消息,您还需要将其添加到Localizable.strings

"Message from %1$@ %2$@ : %1$@" = "Message from %1$@ %2$@ : %1$@";