Andrew Savage Andrew Savage - 2 months ago 5x
iOS Question

My Dynamic CKNotification won't register

I am trying to set up a dynamic

for iOS in Objective-C, but it's failing to register notification.

Here is my code:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"notify == %@",userentry2.text];
CKSubscription *newRecordSub = [[CKSubscription alloc] initWithRecordType:savefolder predicate:predicate options: CKSubscriptionOptionsFiresOnRecordUpdate | CKSubscriptionOptionsFiresOnRecordCreation];
CKNotificationInfo *noteInfo = [CKNotificationInfo new];
noteInfo.alertLocalizationArgs = [NSArray arrayWithObject:@"message"];
noteInfo.shouldBadge = NO;
noteInfo.soundName = UILocalNotificationDefaultSoundName;
newRecordSub.notificationInfo = noteInfo;
CKContainer *container = [CKContainer defaultContainer];
CKDatabase *publicDatabase = [container publicCloudDatabase];
[publicDatabase saveSubscription:newRecordSub completionHandler:^(CKSubscription *subscription, NSError *error) {
NSLog(@"didn't register new notif");
NSLog(@"registered new notif");

When I had just the alert body before, without the
, it would register perfectly, but now that I've added the
functionality it won't register.

Any ideas?


You use either alertBody or you use alertLocalizationKey and alertLocalizationArgs. You don't mix the two.

It's unclear what you want the message to be. Assigning @[ @"message" ] makes no sense in any case.

Either do:

noteInfo.alertBody = @"Some message you create";

or do:

noteInfo.alertLocalizationKey = @"Some Key in your Localized.strings file";
noteInfo.alertLocalizationArgs = @[ @"argument value 1", @"argument value 2" ];

where the localization arguments are values that get substituted like using stringWithFormat: in whatever value is associated with the localization key. The use of the args is only to be used if the localized value takes 1 or more arguments.