xcode 8 push notification capabilities and entitlements file setting

Push NotificationIos10Xcode8Xcode8 Beta6Unnotificationrequest

Push Notification Problem Overview


when using xcode 8 doing the push notification setting, unlike xcode 7, xcode 8 need developer turn on push notifications capabilities switch ( located at TARGETS -> AppName -> Capabilities as following pic ), push notifications capabilities

then it will generate AppName.entitlements file as following

//AppName.entitlements
<key>aps-environment</key>
<string>development</string>

but for production version App, if we change the string to

//AppName.entitlements
<key>aps-environment</key>
<string>production</string>

then the Capabilities show a warning

Capabilities warning

and it seems no matter which string value specified in aps-environment, we can still get the push device token at application:didRegisterForRemoteNotificationsWithDeviceToken:

so what is the correct setting of the push notification entitlements? thank you

Push Notification Solutions


Solution 1 - Push Notification

I was struggling with that today in Xcode 8 GM. After disabling the setting, deleting my developer portal provisioning profile and regenerating it and enabling the setting again, I was able to eliminate the warning in Xcode. Keep in mind that I didn't fiddle with the entitlements file. I left it at development environment and after archiving I got the correct aps-environment setting (production).

Seems Xcode is stilly very buggy tho even in GM

Solution 2 - Push Notification

My problem was my pusher client was out of date and would only push successfully to debug tokens. Other issue which I am still working on a fix for is that I could only export the app via gym with legacy-api enabled, this was not setting the apns-environment to be 'production' and leaving it as 'development' in the 'embedded-mobile.provision' file. I have however been able to successfully deploy the app via the xcode organiser to work with apns(prod) now.

Solution 3 - Push Notification

I think the better solution is open the project package and open project.pbxproj

change the CODE_SIGN_ENTITLEMENTS

CODE_SIGN_ENTITLEMENTS = "your-app/production.entitlements";

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCJ LinView Question on Stackoverflow
Solution 1 - Push NotificationShardonView Answer on Stackoverflow
Solution 2 - Push NotificationPelletView Answer on Stackoverflow
Solution 3 - Push NotificationRainView Answer on Stackoverflow