0

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.
János
  • 32,867
  • 38
  • 193
  • 353
  • Do you sure, that backend for push notification configured correctly and it post push notifications? – Vitalii Gozhenko Dec 13 '14 at 17:41
  • 1
    If you do a accountStatusWithCompletionHandler on the container, what does it return? Does it return the status Available? – Edwin Vermeer Dec 14 '14 at 09:21
  • It returns `Available` – János Dec 16 '14 at 14:03
  • It could be your provisioning profile is not setup right, or perhaps it is but Xcode is using a different provisioning profile (have you got it set to auto-select the profile?): http://stackoverflow.com/questions/10987102/how-to-fix-no-valid-aps-environment-entitlement-string-found-for-application – Abhi Beckert Dec 16 '14 at 20:19
  • I removed all redundant provision files, only one, the valid is there, I turned off **auto-select the profile** and select it **manually** – János Dec 16 '14 at 21:22
  • Just to make sure we have all our t's crossed and i's dotted... can you confirm the push notifications service is active in the provisioning profile? You'll get this error if it's disabled. https://www.dropbox.com/s/hfps3h4sjpks6on/push-notificaions.png?dl=0 – Abhi Beckert Dec 16 '14 at 21:27
  • I haven't found any `push` keyword in the file, I haven't set up `Push Notification` in App IDs in Developer Portal, I red, for `CKSubscription` it is not need, .. strange, what do you think – János Dec 16 '14 at 21:38
  • @Abhi Beckert as on your Dropbox pic, it is turned off for me too, but I am almost 100% sure, that to use `CKSubscription` I do not need set up in Developer Portal CSR and so on .. – János Dec 16 '14 at 21:42
  • Since having it disabled is known to cause exactly this error, you should at least try enabling it. – Abhi Beckert Dec 16 '14 at 21:51
  • @Abhi Beckert push notifications enabled, provision profile regenerated, cleaned, removed temp, etc.. still get aps-environment – János Dec 16 '14 at 22:05
  • app doc says: `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. ` – János Dec 16 '14 at 22:32
  • 1
    @János ok fair enough. There's a reason I posted it as a comment instead of an answer. Also don't trust the documentation, it's often wrong or only applies to old versions of iOS. You have to trust actual behaviour instead — which you've done now. :-) Sorry I don't have anything to offer at this point, except maybe to create a new Xcode project and try to reproduce the bug. – Abhi Beckert Dec 17 '14 at 06:34

2 Answers2

2

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.

János
  • 32,867
  • 38
  • 193
  • 353
0

the error mostly prompts that, the provisioning profile, which you have used, does not support the aps-environment, make sure that you refresh the provisioning profile after you have made modification in your app id,

try this out, open your Provisioning profile in a text editor and search for the following,

aps-environment

if you dont find this, then the problem is provisioning profile associated,if it does then try this out..

How to fix "no valid 'aps-environment' entitlement string found for application" in Xcode 4.3?

Community
  • 1
  • 1
Geet
  • 2,427
  • 2
  • 21
  • 39