Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to get token, error: Error Domain=NSCocoaErrorDomain Code=3000 "no valid 'aps-environment' entitlement string found for application"

Been Stuck on this one issue for quite a while now. Trying to run the following line:

[application registerForRemoteNotifications];

and getting the error

(via: - (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
    NSLog(@"Failed to get token, error: %@", error);
})

2015-04-03 16:06:42.753 TownHall[696:169453] Failed to get token, error: Error Domain=NSCocoaErrorDomain Code=3000 "no valid 'aps-environment' entitlement string found for application" UserInfo=0x17426a1c0 {NSLocalizedDescription=no valid 'aps-environment' entitlement string found for application}

Tried some of the stuff with the following associated post http://stackoverflow.com/questions/10987102/how-to-fix-no-valid-aps-environment-entitlement-string-found-for-application but little luck. 

This includes: 1) Recreating a provisioning profile 2) Recreating ID and checking that it matches and has push enabled 3) Clean and rebuild, etc 4) Creating of new certificates 5) Refresh with Xcode > Preferences > Accounts > View Details (Select your account)

Wondering if anyone has any solutions for this?

Happy to share any other information that people might find useful for solving this problem.

Thanks a lot in advance for help!

like image 749
John Avatar asked Apr 03 '15 22:04

John


2 Answers

Go to your projects Target under Capabilities section, you'll find this error glowing. XCode may suggest to fix it for you automatically.enter image description here

You'll have to create a two entitlements(AppName_Debug.entitlements and AppName_Release.entitlements) file within your project with the following content: AppName_Debug.entitlements

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
 "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
      <dict>
        <key>aps-environment</key>
          <string>development</string>
      </dict>
</plist>

AppName_Release.entitlements

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
 "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
      <dict>
        <key>aps-environment</key>
          <string>production</string>
      </dict>
</plist>

Add these two files under Code Signing Entitlments in Build Settings under appropriate option.

enter image description here

like image 138
mickeymoon Avatar answered Sep 20 '22 11:09

mickeymoon


You don't have a valid provisioning profile or team is none

like image 35
nahlamortada Avatar answered Sep 18 '22 11:09

nahlamortada