bashan
bashan

Reputation: 3602

no valid 'aps-environment' entitlement string found for application

I am trying to configure my app to support push notification, but keep getting this error: Failed to get token, error: Error Domain=NSCocoaErrorDomain Code=3000 "no valid 'aps-environment' entitlement string found for application" UserInfo=0x1f818fc0 {NSLocalizedDescription=no valid 'aps-environment' entitlement string found for application}

Any more ideas? Thanks.

Upvotes: 84

Views: 68977

Answers (11)

bittu
bittu

Reputation: 713

For those who got this error in ios 10, you can try following steps:

1.clean your project.
2.and check Targets -> Capabilities -> Push Notification.If it is off,On it.

And problem will solve.The above steps help me to get rid off this problem. Hope it will helpful to someone.

Upvotes: 2

Lucas van Dongen
Lucas van Dongen

Reputation: 9848

If this problem happened suddenly after upgrading to Xcode 8 you might find a warning in the capabilities screen that'll allow you to fix this automatically:

Select Project > Target > Capabilities > Turn On Push notifications

Upvotes: 3

error-404
error-404

Reputation: 229

I fixed this problem by enabling push notification capability.

Select Project > Target > Capabilities > Turn On Push notifications

check out the image

Upvotes: 9

Oren
Oren

Reputation: 5103

I had this same problem after push notifications were already working on my device. Seemed like Xcode cached something incorrectly so refreshing it fixed my problem:

  1. Xcode -> Preferences -> Accounts
  2. View Details for your Developer Account
  3. Just click Refresh for the Provision Profiles a few times. I was seeing these change with each refresh. Keep refreshing until they stop changing.

Upvotes: 28

user3344717
user3344717

Reputation: 161

New provisioning profile worked for me. Make sure to use a Developer profile if you are in development (don't use Ad Hoc). It was fine after that, no idea why the old one stopped working right.

Upvotes: 0

KevinH
KevinH

Reputation: 2044

I ran into this in what's possibly a non-frequent use case. I'm working with Xcode 6 and iOS 8. I was creating a series of entirely new app projects, and attempting to re-use the same bundle ID, so as not to need to go through all of the portal-side setup again. This too was just for sandbox testing.

I would find that, while the setup and registration would work fine for the first app, if I deleted that app from the device, set the same bundle ID for the second app, and then attempted to register PNs with that app, I would get this error.

My solution was to:

  1. Remove the associated provisioning profile from the device.
  2. Remove the associated provisioning profile from Xcode.
  3. Close Xcode
  4. Double-click my downloaded .mobileprovision file to install it back into Xcode
  5. Open the project and deploy it.

This approach seems to jar loose whatever previous state was there, and I'm able to register for PNs with the new app / same bundle ID.

Upvotes: 2

Louis Cremen
Louis Cremen

Reputation: 764

Product->Clean did it for me. Hopefully it does it for someone else.

Upvotes: 2

sudo
sudo

Reputation: 5784

Be aware that the bundle identifier must match the provisioning profile in a case-sensitive manner. I had something like com.FirstLast.appname when it should have been com.firstlast.appname. Well, that kept me busy for quite a while.

Upvotes: 9

Raptor
Raptor

Reputation: 54212

The problem is due to current Provisioning Profile does not contain APNS information, as the Provisioning Profile is created BEFORE creating the APNS certificate.

Therefore, to solve the problem, create a new Provisioning Profile & select the Provisioning Profile in Xcode will clear the error.

Upvotes: 37

jasonpurdy
jasonpurdy

Reputation: 151

i got this error and did not create a new provisioning profile; created a new one and then had to restart xCode but works now!

Upvotes: 9

Drew
Drew

Reputation: 8963

In my case, the stuff in my provisioning profile:

security cms -D -i ~/Downloads/spolskyDevelop.mobileprovision 
...
<key>application-identifier</key>
<string>P5GM95Q9VV.com.dca.spolsky</string>
<key>aps-environment</key>
<string>development</string>

Was different than the stuff in the app that was actually built (you can find out where it is built by looking at Xcode's Logs tab)

codesign -d --entitlements - '/Users/drew/Library/Developer/Xcode/DerivedData/spolsky-bdbtdfjeeywhqzccpmmceqvnhgtm/Build/Products/Debug-iphoneos/spolsky-ios.app'
<dict>
    <key>application-identifier</key>
    <string>Y2X6Z7Z2GR.com.dca.spolsky-ios</string>
    <key>get-task-allow</key>
    <true/>
    <key>keychain-access-groups</key>
    <array>
        <string>Y2X6Z7Z2GR.com.dca.spolsky-ios</string>
    </array>
</dict>

This was true even though the "Currently Matches" hint text under Code Signing Identity was indicating the correct provisioning profile--weird, huh? To make a weird story weirder, the correct provisioning profile was being installed on the device when I ran, (Settings->General->Profiles) leading me to believe the provisioning profile was right--but it was falling back to a wildcard ID when the app was actually launched.

The clue was the difference in the output of these two commands:

Y2X6Z7Z2GR.com.dca.spolsky-ios vs P5GM95Q9VV.com.dca.spolsky

When I made the bolded part match, the italicized part changed to match automatically. In addition, the output of security and codesign were in agreement, and no more aps-entitlement error.

My guess here is that XCode was using a wildcard-style match on my non-wildcard ID. ("spolsky" is, after all, quite nearly "spolsky-ios"), and this explains the "Currently Matches" output. But something in the build chain is more strict about this, so it falls back to an actual wildcard ID during the build.

Upvotes: 64

Related Questions