2
votes

I have an app that I'm building, and I'm trying to keep track of a subscription using Cloudkit. I have a RecordType called Notifications with one field of type String called NotificationText. For some reason, when I add a new record, the app does not receive it. Here's what I have done so far:

  1. Registered for Cloudkit in the "Capabilities" section of the app.
  2. Added the Required background modes key to the info.plist file for remote-notifications
  3. Saved the Subscription to the database using:

    CKSubscription *subscription = [[CKSubscription alloc]
                                    initWithRecordType:@"Notifications"
                                    predicate:[NSPredicate predicateWithValue:YES]
                                    options:CKSubscriptionOptionsFiresOnRecordCreation];
    
    CKNotificationInfo *notificationInfo = [CKNotificationInfo new];
    notificationInfo.alertLocalizationKey = @"NotificationText";
    notificationInfo.shouldBadge = YES;
    notificationInfo.soundName = @"";
    
    subscription.notificationInfo = notificationInfo;
    [publicDB saveSubscription:subscription
             completionHandler:^(CKSubscription *subscription, NSError *error) {
                 if (error)
                     [self handleError:error];
    
                 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"sub"];
    
             }
     ];
    
  4. Requested permission from the user to send push notifications using:

    UIApplication *application = [UIApplication sharedApplication];
    UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert categories:nil];
    [application registerUserNotificationSettings:notificationSettings];
    [application registerForRemoteNotifications];
    
  5. Implemented the -(void)application:(UIApplication *)application didReceiveRemoteNotification:(non null NSDictionary *)userInfo fetchCompletionHandler:(non null void (^)(UIBackgroundFetchResult))completionHandler; in the AppDelegate.m file.

Now I go into the Cloudkit Dashboard and create a new record of RecordType Notifications, and nothing happens. Am I doing something wrong? Am I missing something?

1

1 Answers

1
votes

After much searching and banging my head against a wall, I found my problem.

PUSH NOTIFICATIONS DO NOT WORK ON SIMULATORS!

I hooked up an iPod to the app and, bang! Notification was received.