问题
Push notifications are working fine when using development certificates. When I switched to a production certificate in my ad-hoc distribution the app fails to register for push notifications. In the UIApplicationDelegate, neither didRegisterForRemoteNotificationsWithDeviceToken nor didFailToRegisterForRemoteNotificationsWithError get called. Additionally when I took a look at the device logs I found this:
Sep 30 12:47:09 Heshams-iPad amfid[483] <Error>: entitlement 'aps-environment' has value not permitted by a provisioning profile
Sep 30 12:47:09 Heshams-iPad amfid[483] <Error>: entitlement 'application-identifier' has value not permitted by a provisioning profile
Sep 30 12:47:09 Heshams-iPad amfid[483] <Error>: entitlement 'aps-environment' has value not permitted by a provisioning profile
Sep 30 12:47:09 Heshams-iPad amfid[483] <Error>: entitlement 'aps-environment' has value not permitted by a provisioning profile
Sep 30 12:47:09 Heshams-iPad amfid[483] <Error>: entitlement 'application-identifier' has value not permitted by a provisioning profile
My entitlements key in the provisioning profile looks like this:
<key>Entitlements</key>
<dict>
<key>application-identifier</key>
<string>KUK8W9TW2G.com.startappz.ConversableDemo</string>
<key>aps-environment</key>
<string>production</string>
<key>get-task-allow</key>
<false/>
<key>keychain-access-groups</key>
<array>
<string>KUK8W9TW2G.*</string>
</array>
</dict>
I have tried deleting the provisioning profiles from both Xcode and the portal and recreating them, I have also tried revoking the certificates and recreating them. I have even changed the app id and did everything from scratch.
I have also tried building with and without a separate entitlements file.
Update
I'm now debugging on the device using a distribution provisioning profile. The app now registers and receives push notifications successfully on the production servers, but still archiving the app breaks push notifications.
So now I'm almost sure Xcode is messing up something when archiving the app.
回答1:
Have you changed the APNS Script in your server?
ssl://gateway.sandbox.push.apple.com:2195 needs to be; ssl://gateway.push.aple.com:2195 and
development_certificate.pem should be; production_certificate.pem
回答2:
I was guessing right, Xcode was indeed messing up something when archiving the app. After selecting "Save for Enterprise or Ad-Hoc Deployment", the code signing identity drop down menu was showing my team name as '(null)'.
After refreshing the code signing identities it's now showing up properly and the ad-hoc ipa now registers and receives push notifications normally on my device.
来源:https://stackoverflow.com/questions/12660931/cant-register-for-push-notifications-while-using-production-certificate-only