János
János

Reputation: 35038

Show notification specific message with CKSubscription / CKNotificationInfo?

I want to notify user that a chat message has been sent from an other user, and the body of the notification should be the message. Is it a way to set it with CKSubscription / CKNotificationInfo? Like alertBody, but specific for each message. Any idea how?

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)

Upvotes: 0

Views: 451

Answers (1)

Edwin Vermeer
Edwin Vermeer

Reputation: 13127

You can use parameters in your alert like this:

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

Since this is a lokalized message you also need to add it to Localizable.strings

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

Upvotes: 1

Related Questions