Search code examples
iosapple-push-notificationscloudkitcksubscription

CloudKit + no valid aps-environment entitlement error


I try to use CloudKit subscriptions in my app, but didReceiveRemoteNotification not get triggered.

I saved CKSubscription to CloudKit. To be sure they exists, when app starts, I plot them out, like:

<CKSubscription: 0x15576310; ; Query Subscription: recordType=DailyVote, predicate=TRUEPREDICATE, subscriptionOptions=7, subscriptionID=1FA456A6-9BA5-411D-97B9-1EB57121A5D0, zoneID=(null)> predicate: TRUEPREDICATE subscriptionType: (Enum Value) subscriptionOptions: C.CKSubscriptionOptions

I try to register my device at APN server, as apple doc recommend, but error delegate method get called, with message:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Alert, categories: nil))
    application.registerForRemoteNotifications()

    return true
}

func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {

    println("error: \(error.localizedDescription)")
    //error: no valid aps-environment entitlement found for application
}
  • CloudKit capability is on
  • I have no invalid provision profile
  • I have done the trick: Xcode > Preferences > Accounts > pick your Account > pick your Team > View Details > PRESS REFRESH BUTTON
  • I even created a fresh App, with new iCloud Container, moved all the logic, but the error is the same and subscription notification does not work.

Solution

  • Even though Apple Doc says here: You don’t need to enable push notifications for the app’s explicit App ID in Member Center to receive subscription notifications. Xcode automatically adds the APNs entitlement to your entitlement file when you enable CloudKit.

    If you add Push Notification in Developer Portal under App IDs it will work, or at least for second try for me it worked.