2

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.