CloudKit subscription notifications in the background

I am using CloudKit subscriptions and successfully receive the remote notifications while the device is actively running my app. However, it doesn't seem to work if the app isn't active on that device, and I'm not sure how to debug this. From the WWDC 2015 "CloudKit Tips and Tricks" talk, all I need to do is enable the "Remote Notifications" background mode, which I have done. It also mentioned something about setting aps-environment, which I don't have in my entitlements file (though push notifications still work fine, just not in the background).

When I use the "Launch due to background fetch event" checkbox in Xcode schemes, and try to run the app on my iPhone (not simulator), the app doesn't launch ... I get an error message in Xcode saying "Could not launch 'TestApp' ... process launch failed: Disabled" . It works fine if I have this checkbox unselected, and I receive notifications as long as the app is active, but if I stop the debugger, I can't tell if the app is receiveing any notifications anymore.


What do I need to do to test and debug CloudKit subscribtion notifications in the background?

To receive a notification you need to do a few things. You need to get CloudKit to send a notification to your device by registering with CloudKit - you did that because you get the notifications when the app is running. You also need to tell Settings to allow your app to receive a notiifcation by launching the Settings App from the Home screen, select \"Notifications\" then select the App and then tap \"Allow Notifications\"."


and you need to do this within the app:

      UIUserNotificationType types = UIUserNotificationTypeSound | UIUserNotificationTypeBadge | UIUserNotificationTypeAlert;
      UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
      [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
      [[UIApplication sharedApplication] registerForRemoteNotifications];


After that, if the app is in the background then a notice will appear on the app. If you swipe that notice then the device will move the app to the foreground and call application:didReceiveLocalNotification:


This stuff is explained here:

https://developer.apple.com/library/mac/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/WhatAreRemoteNotif.html#//apple_ref/doc/uid/TP40008194-CH102-SW1

CloudKit subscription notifications in the background
 
 
Q