How to fix "no valid 'aps-environment' entitlement string found for application" in Xcode 4.3?

182,244

Solution 1

The answer was: start over, do everything the same but create a new provisioning profile, and install it. That worked. Inspecting all the details (entitlements in mobile provision) looks exactly the same as everything in my question here. But now it works. Apple: WAT?

Of course, it would have been obvious to do this if it was possible to delete provisioning profiles. But since that's not possible, I didn't want to clutter our team with a bunch of test profiles. Still, finally lost patience and tried it anyway, and it ended up working. Whatevs.

Solution 2

If you created your provisioning profile before configuring the app ID for push, try to regenerate the provisioning profile.

iOS Provisioning Portal -> Provisioning -> Your cert -> EDIT -> Make an edit -> Download new provisioning

Worked for me. Now i'm able to use push.

Solution 3

First of all, you don't need the entitlements file unless you are adding custom key/value pairs that do not exist in the provisioning profile. When your app is built, any entitlements from the provisioning profile will be copied to the app.

Given that you still see an error message about missing entitlements, I can only assume the code signing options are not correct in the build settings.

You need to make sure the correct profile is selected for the "Debug" configuration, and to be safe, that you have selected the correct profile for both the "Debug" and child-node labelled "Any iOS SDK":

enter image description here

Although this screenshot shows the "Automatic Developer" profile selected, choose the exact provisioning profile you want from the drop down, just for testing purposes. It could be that Xcode is automatically choosing a different profile than the one you want.

Also be sure to do a clean build, completely delete the app from your device, etc. This is just to make sure you don't have some old fluff hanging around.

Solution 4

I have faced this issue in Xcode 8. You must have to enable Target—> capabilities—> push notification. Check the screenshot.

enter image description here

Solution 5

Easiest way is to do this from your accounts with Xcode:

Head over Xcode -> Preferences -> Choose Accounts Tab -> View Details -> Hit refresh button on the bottom left -> Done.

Build again and it should work.

Share:
182,244

Related videos on Youtube

jwl
Author by

jwl

Updated on July 08, 2022

Comments

  • jwl
    jwl almost 2 years

    I've been trying very very hard to create a simple simple iOS app which can recieve push notifications. My only reason for doing this is to establish a procedure for some other team members to use, and have not been able to find an up to date, working version of such instructions elsewhere on the web. Our shop is fairly new to iOS dev, I personally am completely inexperienced with iOS dev and Xcode. I've stumbled through tens of tutorials, articles, and trouble posts from Apple and elsewhere and I feel like I might be nearly there...

    Here is where I've got to (note I'm using Xcode 4.3 and trying initially to deploy just to iOS 5.1, and I gather that some things may have changed recently vs earlier versions of Xcode, but again I'm new to all this -- and finding it completely confusing and convoluted):

    1) I've got a provisioning profile on my iPhone which has Push enabled

    2) In my test Xcode project I've got that provisioning profile selected as the signing identity (in Build Settings > Code Signing)

    enter image description here

    3) I've got my bundle identifier under Summary and Info > Custom iOS Target Properties set properly* (I think??)

    4) I've got registerForRemoteNotificationTypes being called in my delegate's didFinishLaunchingWithOptions

    5) I've got didRegisterForRemoteNotificationsWithDeviceToken and didFailToRegisterForRemoteNotificationsWithError in my delegate, set up to log the device token or error respectively

    6) I've got Enable Entitlements checked under Summary.

    7) Right below that the Entitlements File selected is Tinker6 (the name of my test project), which was generated automatically when I checked Enable Entitlements

    8) In the Tinker6.entitlements file I've got the following (which I've gathered is correct based on several different posts all over the web, but which I can't find anything definitive from Apple itself on):

    enter image description here

    Updated

    9) Also, I have tried the whole thing without an entitlements file, and get essentially the same result.

    10) My mobileprovision file contents include entitlements properly (I've scrambled the number and domain but structurally the same):

    <key>application-identifier</key>
    <string>12355456A7.com.whatever.tinker</string>
    <key>aps-environment</key>
    <string>development</string>
    <key>get-task-allow</key>
    <true/>
    <key>keychain-access-groups</key>
    <array>
        <string>12355456A7.*</string>
    </array>
    

    /end update

    When I attempt to run this on my device, I get the following error in Xcode output:

    2012-06-11 12:45:23.762 Tinker6[13332:707] Failed to get token, error: 
    Error Domain=NSCocoaErrorDomain Code=3000 "no valid 'aps-environment' 
    entitlement string found for application" UserInfo=0x24a3b0 
    {NSLocalizedDescription=no valid 'aps-environment' entitlement string 
    found for application}
    

    I've tried setting get-task-allow to NO, aps-environment to production, all four possible combinations, same thing.

    How can I get past this? Where is definitive documentation on this?

    -- further background follows --

    *As far as the bundle id, I am still not clear on how this should be set in relation to App Ids and Profile ids in the Provisioning profile. In the Provisioning portal under App Ids I have this (again, scrambled the number and domain):

    enter image description here

    And the two places bundle id is set I have this:

    enter image description here enter image description here

    I am not at all sure these are correct or whether one or both should be set to 12355456A7.com.whatever.tinker, though I've tried those earlier in the process with no success...

    Note I realize there are many posts with similar titles, however they all seem to be out of date based on the file names and so-forth given, and the fact none of the solutions seem to be useful. I'm hoping the greater level of detail I've given will warrant a quality response. I will probably assign a bounty as soon as possible and if you give a high quality answer that leads to a solution I will award you the bounty as well as promote your answer via twitter and my blog. Especially if you crosspost post a really good "here are the exact 500 steps you need to get a simple push notification app working including provisioning and whatever else" article on your blog or whatever.

  • jwl
    jwl about 12 years
    If entitlements are a legacy thing then why am I getting a message complaining about no entitlements? I have already followed the linked tutorial to the letter with no luck... thanks though.
  • jwl
    jwl about 12 years
    Also, I've added some info about the actual mobileprovision file which could be useful.
  • X Slash
    X Slash about 12 years
    that's true, I don't even setup any .entitlements to successfully push notifications. One thing that tripped me when I was doing it was that I need to download the mobileprovision manually, then go to build settings and change signing identity to matched the one that's just downloaded, in my case, apparently Xcode is picking the wild card mobileprovision.
  • jwl
    jwl about 12 years
    Per #2 in my post, it is set correctly I think, though I've added a clarifying screenshot to verify. I've also tried removing the app completely and leaving it off for 2 days per a recommendation I saw somewhere that it takes a day for some info to get reset (yes, I'm grasping at straws!?). But when you say "You need to make sure the correct profile is selected for the "Debug" configuration" what exactly do you mean -- where do I select that?
  • Mike Weller
    Mike Weller about 12 years
    If you click on the "iPhone Developer" part, or whatever is set as the current value, you will see a dropdown of all the provisioning profiles that Xcode knows about. Make sure the correct one is selected, or that the "Automatic Developer" item is choosing the correct one. The dropdown should show you everything.
  • Gruntcakes
    Gruntcakes about 12 years
    I too got an error message about entitlements a while ago, its a red herring, see Mike Wellers response, that is what I did in my case.
  • Gruntcakes
    Gruntcakes about 12 years
    I've updated the answer with some more things for you to check.
  • jwl
    jwl about 12 years
    can you be more explicit regarding what exactly "regenerate the provisioning profile" entails? Is this a step in XCode, in the Provisioning Portal, where? thanks!
  • Mike Weller
    Mike Weller about 12 years
    And are you sure you have the latest provisioning profile? Could it be that you have an old version, from before push was enabled?
  • jwl
    jwl about 12 years
    Well, yes I believe so. What I have done to obtain the new provisioning profile is to, in Xcode Organizer, delete the profile from both the Library and from the device, and then back on the Library screen clicked Refresh. This pulled it back down from the Provisioning Portal. I then added this to the device. And as shown above, the mobileprovision file XML ish content shows the correct entitements
  • elp
    elp about 12 years
    In the portal. Simply add or remove a device and your provisioning will be generated. After that, double click and install in your keychain.
  • Mike Weller
    Mike Weller about 12 years
    OK, in Xcode right-click on the .app under the "Products" group in the left-hand navigator. Select show in finder. This should take you to the .app. Run this command: codesign -d --entitlements /path/to/the.app. This will dump out the entitlements for the app and show you exactly what Xcode has used.
  • jwl
    jwl about 12 years
    interesting suggestion. However, when I run codesign -d --entitlements /Users..stuff..../Build/Products/Debug-iphoneos/Tinker6.app, I get shown the command usage Usage: codesign.... output. I've tried --display --entitlements, I've tried cd-ing into the directory and using codesign -d --entitlements Tinker6.app, and every relavent combination with the same output. This stackoverflow.com/questions/2261404/… suggests I update OS and/or Xcode, but this is most up to date Lion & Xcode... weirdness
  • jwl
    jwl about 12 years
    sorry if I'm being dense, but add/remove it under Devices? Or somewhere beneath the actual Provisioning Profile in question, and if so exactly where?
  • Mike Weller
    Mike Weller about 12 years
    Ach, sorry. There needs to be a - before the path: codesign -d --entitlements - /path/to/my.app. It's also worth it at this point to double check that you are in the Debug-iphoneos directory, since "Show In Finder" can sometimes take you to the wrong place.
  • elp
    elp about 12 years
    Adding or removing devices is a trick to regenerate your provisioning. You need to regenerate one to use push notification, because it's linked to app id and push certicate..
  • jwl
    jwl about 12 years
    Thanks! What came back was basically exactly what is shown below my "10)" above. pastebin.com/DSMrJvRD (again, some of the relavent data is scrambled because I don't know what kind of security exposure is involved, but structurally the same)
  • Mike Weller
    Mike Weller about 12 years
    OK, well that should work. Open the Xcode organizer and drag the .app file over your device. Just so we know this exact app will be installed to the device. Then try running it and look in the Console for any errors etc.
  • jwl
    jwl about 12 years
    awarding you the bounty because you've put the most effort into this, however the answer is a bit different
  • Mike Weller
    Mike Weller about 12 years
    I'd be happy to continue helping you with this issue. Perhaps we can take this outside SO. Maybe even set up some screen sharing so I can take a closer look?
  • jwl
    jwl about 12 years
    I may have been unclear. I've solved the problem (see the checked answer now) by starting over from scratch. But I'm giving you the bounty for your effort. Thanks!
  • matt
    matt over 11 years
    But this adds nothing to the existing answers, which already give this advice. Obviously a push app needs its own profile; the docs are quite clear that the wildcard profile can't be used for any app that needs special entitlements.
  • scurioni
    scurioni over 11 years
    Creating a new profile and "dirtying" the old one like it is said in this other SO question worked for me: stackoverflow.com/questions/5681172/…
  • JavaCoderEx
    JavaCoderEx about 11 years
    This was my fault but fixed it using this method. I had accidentally put in the info box a different identifier from what I generated the certificate with.
  • odyth
    odyth about 11 years
    All I had to do was delete the existing provisioning profile out of the portal and recreate it. You can delete profiles now after the update so no need to create a new app id.
  • Michael
    Michael over 10 years
    I had this issue as well. Xcode 5 is pretty good at updating any provisioning profiles. I added the APNS service later in development. You have to make sure as the above poster points out that your provisioning profile is actually the profile that is unique to the app you are working on and not a wild card one.
  • Ian Jamieson
    Ian Jamieson over 10 years
    I have done this, but my app will only ever select the wildcard provisioning profile, I can't force it to select the one with push notifications enabled.
  • Ian Jamieson
    Ian Jamieson over 10 years
    @Michael, how do you make sure of this? I have tried changing it in my build settings (under Code Signing), which is currently set to none. When i choose the correct profile and build, it comes up with an error and then goes back to the wildcard provisioning profile.
  • Michael
    Michael over 10 years
    @ian what error are you getting? Are you sure it is a valid profile?
  • Ian Jamieson
    Ian Jamieson over 10 years
    Ah, I have sorted it, I needed to re download the correct certificate to my Mac. That seems to have done the trick. Thanks.
  • Michael
    Michael over 10 years
    Glad to hear it. That what I usually do when it seems the settings are correct. Redo all the certs. Seems to be the issue more times than not.
  • Ajeet
    Ajeet almost 10 years
    i have been facing the same problem. Just wanted to ask, does the path-to-app is for app installed on simulator?
  • retromuz
    retromuz over 9 years
    This is the one worked for me too. Editing the old provisioning profile and downloading did not work for me. Thanks!
  • dwery
    dwery over 9 years
    no, it's the path of the compiled app for the actual device, in the xcode build directory.
  • ritmatter
    ritmatter about 9 years
    As a helpful addendum, rather than getting an new provisioning profile, I was simply able to delete the old one
  • fatuhoku
    fatuhoku about 9 years
    I would highly recommend not doing it by hand. Use github.com/fastlane/PEM.
  • Nazik
    Nazik over 8 years
    New provisioning profile with same app id and distribution certificate fixed the issue for me. +1 :)
  • inVINCEable
    inVINCEable almost 8 years
    Was racking my head on this, I guess when i switched to the Xcode 8 beta it turned off my push notifications switch or something. Thanks
  • Ethan Long
    Ethan Long almost 8 years
    Thanks, this is why I had this problem. My app ID is enabled for in-app-purchase, game-center etc, but in Xcode/capabilities they are all turned off before, no problem. Ever since updated to Xcode 8 I'm having this problem. After enable IAP and game center in Xcode, the problem is gone!
  • Veck Hsiao
    Veck Hsiao over 7 years
    This help me!!!! Just click a button... solving my problem that I debugging for hours... Xcode8, too.
  • Ferran Maylinch
    Ferran Maylinch over 7 years
    OMG thank you! Come on Apple, give us a more reasonable error message!
  • Kevin
    Kevin over 7 years
    Xcode 8 turned off Push notifications for my app, so this solution worked.
  • Collin Flynn
    Collin Flynn over 7 years
    Thank you, I must have done the other setup steps 3 times before I found this. I feel like an idiot, but also that the tools are bad for allowing this to be the problem.
  • oskarko
    oskarko almost 7 years
    you saved my day, mate!
  • brichins
    brichins over 6 years
    Wish your screenshot had included the sidebar - took me a bit to figure out that it is showing settings for a specific Target, not the overall Project.