I am encountering this error when I am loading an Ad Hoc build of my Push Notification enabled iPhone app onto my device:
no valid aps-environment entitle
I found the solution. In my project info under Build > Code Signing Identity I had it set to automatic, and it was selecting an AdHoc distribution profile which did not have push notifications enabled. (It was the wrong one.) I have selected the correct profile and the error is gone.
Push Notifications must be enabled for your App ID before creating a Provision Profile.
So, in this order:
Create your APP ID
Enable APNS
Create the Provisioning Profile
In my case Xcode had invalidated the provisioning profile (it will say so in the Member Center).
What worked was to refresh all the provisioning profiles in Xcode after enabling Push for the app in the Member Center.
Here is Apples guide to refresh all the provisioning profiles on your computer. https://developer.apple.com/library/prerelease/ios/documentation/IDEs/Conceptual/AppDistributionGuide/MaintainingProfiles/MaintainingProfiles.html#//apple_ref/doc/uid/TP40012582-CH30-SW26
In short open Xcode and do the following:
In the Xcode Preferences window, click Accounts.
Select your team, and click View Details.
In the dialog that appears, click the Refresh button in the lower-left corner under the Provisioning Profiles table.
Xcode updates the list of profiles in the Provisioning Profiles table.
if you didn't write the original code and aren't 100% sure on how it works, make sure that you have it set up to receive the right type of push notification token. had a problem where the app i was working on was only set up tokens on a release build. it's worth a try if nothing else works and you think your code is set up properly -- find the steps online somewhere to do a ad-hoc build and try it
You have to enable Target—> capabilities—> push notification. I have faced this issue using Xcode 8.1.
It'll work even with a development profile but if you add in APN (Apple Push Notifications) after the fact make sure to go into member center and open the provisioning profile again (my said invalid), just opening it and closing it made it valid again and then I updated my profiles in Xcode via settings and everything worked just fine.