159

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
  • 10,268
  • 14
  • 53
  • 91
  • Duplicate post, I found my solution here: https://stackoverflow.com/questions/27324020/no-valid-aps-environment-entitlement-string-found-for-application-on-app-store – gadildafissh Mar 19 '22 at 18:07

24 Answers24

95

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.

elp
  • 8,021
  • 7
  • 61
  • 120
  • 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! – jwl Jun 18 '12 at 15:13
  • 2
    In the portal. Simply add or remove a device and your provisioning will be generated. After that, double click and install in your keychain. – elp Jun 18 '12 at 15:42
  • 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? – jwl Jun 18 '12 at 23:47
  • 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.. – elp Jun 19 '12 at 07:52
71

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.

Mike Weller
  • 45,401
  • 15
  • 131
  • 151
  • 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? – jwl Jun 14 '12 at 14:57
  • 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. – Mike Weller Jun 14 '12 at 15:02
  • And are you sure you have the latest provisioning profile? Could it be that you have an old version, from before push was enabled? – Mike Weller Jun 18 '12 at 15:19
  • 2
    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 – jwl Jun 18 '12 at 15:36
  • 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. – Mike Weller Jun 18 '12 at 15:49
  • 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 http://stackoverflow.com/questions/2261404/codesign-unrecognized-option-entitlements suggests I update OS and/or Xcode, but this is most up to date Lion & Xcode... weirdness – jwl Jun 18 '12 at 23:40
  • 3
    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. – Mike Weller Jun 19 '12 at 07:03
  • Thanks! What came back was basically exactly what is shown below my "10)" above. http://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) – jwl Jun 19 '12 at 14:42
  • 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. – Mike Weller Jun 19 '12 at 14:53
  • awarding you the bounty because you've put the most effort into this, however the answer is a bit different – jwl Jun 19 '12 at 16:18
  • 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? – Mike Weller Jun 19 '12 at 20:14
  • 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! – jwl Jun 19 '12 at 22:21
67

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

enter image description here

DipakSonara
  • 2,598
  • 3
  • 29
  • 34
  • 1
    This help me!!!! Just click a button... solving my problem that I debugging for hours... Xcode8, too. – Veck Hsiao Oct 08 '16 at 20:40
  • 3
    OMG thank you! Come on Apple, give us a more reasonable error message! – Ferran Maylinch Oct 10 '16 at 15:09
  • Xcode 8 turned off Push notifications for my app, so this solution worked. – Kevin Oct 22 '16 at 00:33
  • 1
    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. – Collin Flynn Nov 10 '16 at 16:43
  • 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. – brichins Oct 25 '17 at 16:21
47

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.

ooxio
  • 806
  • 1
  • 10
  • 13
19

Ok, I faced the problem before. Since push notification requires serverside implementation, for me recreating profile was not an option. So I found this solution WITHOUT creating new provisioning profile.

Xcode is not properly selecting the correct provisioning profile although we are selecting it correctly.

First go to organizer. On the Devices tab, Provisioning profile from Library list, select the intended profile we are trying to use. Right click on it and then "Reveal Profile in Finder".

enter image description here

The correct profile will be selected in the opened Finder window. Note the name.

enter image description here

Now go to Xcode > Log Navigator. Select filter for "All" and "All Messages". Now in the last phase(Build Target) look for the step called "ProcessProductPackaging" expand it. Note the provisioning profile name. They should NOT match if you are having the error. enter image description here

Now in the Opened Finder window delete the rogue provisioning profile which Xcode is using. Now build again. The error should be resolved. If not repeat the process to find another rogue profile to remove it.

Hope this helps.

Max
  • 3,371
  • 2
  • 29
  • 30
  • 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. – JavaCoderEx Apr 09 '13 at 20:29
18

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.

jwl
  • 10,268
  • 14
  • 53
  • 91
  • Creating a new profile and "dirtying" the old one like it is said in this other SO question worked for me: http://stackoverflow.com/questions/5681172/bundle-identifier-and-push-certificate-aps-environment-entitlement-error – scurioni Jan 22 '13 at 02:30
  • 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. – odyth May 07 '13 at 03:36
  • New provisioning profile with same app id and distribution certificate fixed the issue for me. +1 :) – Nazik Jan 20 '16 at 09:50
18

Delete old provisioning profile from XCode in Organizer.

Then, generate a new provisioning profile for the same bundle id in iOS provisioning portal (after you have enabled push).

Import the new provisioning profile in XCode, set it in your app build settings.

Build, run, it works.

I just did it.

It took me 10 minutes from error to success.

user229044
  • 232,980
  • 40
  • 330
  • 338
user1006117
  • 431
  • 4
  • 16
  • This is the one worked for me too. Editing the old provisioning profile and downloading did not work for me. Thanks! – retromuz Oct 10 '14 at 05:17
  • As a helpful addendum, rather than getting an new provisioning profile, I was simply able to delete the old one – ritmatter May 26 '15 at 16:22
  • 1
    I would highly recommend not doing it by hand. Use https://github.com/fastlane/PEM. – fatuhoku Jun 20 '15 at 14:33
17

XCode 6.1.1, and multiple apple developer accounts

Another answer for this already fairly comprehensive mix: I came across this issue again today, and this time it was due to my having multiple apple accounts. I needed to first add the 2nd developer account in XCode > Preferences > Accounts > +

Ensure that the Push Notification Capability is ON

Next I needed to actually explicitly enable In-App Purchase in the app (I did not need to do this previously). XCode > (the app window) > Targets > Capabilities > In-App Purchase ON (and at this stage I was given the option to choose the correct certificate)

Note that I had already added the Push enabled certificate by double clicking it in Finder.

enter image description here

Community
  • 1
  • 1
kris
  • 11,868
  • 9
  • 88
  • 110
  • 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 – inVINCEable Jul 12 '16 at 14:21
  • 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! – Ethan Long Sep 20 '16 at 01:41
11

(Xcode 5) Well, after spending an hour I solved my issue. Even if you re-generate the provisioning file in Xcode 5, you should manually update your account. I only changed provisioning file in the Organizer tab that did not work, Xcode kept build with old provisioning file.

So go to

Xcode > Preferences > Accounts > View Details (Select your account)

Then refresh your provisioning files.

Ömer Faruk Almalı
  • 3,792
  • 6
  • 37
  • 63
8

My problem was simply that I was signing with the Xcode-managed wildcard provisioning profile.

After I created an app-specific profile (and downloaded it, double-clicked it, and ensured my Build Settings referred to it), I successfully received an APNS device token.

Graham Perks
  • 23,007
  • 8
  • 61
  • 83
  • 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. – Michael Jan 21 '14 at 05:14
  • @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. – Ian Jamieson Feb 14 '14 at 16:17
  • @ian what error are you getting? Are you sure it is a valid profile? – Michael Feb 14 '14 at 18:57
  • Ah, I have sorted it, I needed to re download the correct certificate to my Mac. That seems to have done the trick. Thanks. – Ian Jamieson Feb 17 '14 at 10:44
  • 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. – Michael Feb 18 '14 at 18:48
7

I had the same issue was everyone else and tried all the above tricks, nothing worked. I even deleted and started fresh with a different developer account.

What worked for me in the end was

  1. Do as suggested above and create APP ID
  2. Then create provisioning profile
  3. DO NOT use the team wildcard profile (managed by xcode one) in the development section of the provisioning. You need to make a separate one using that app ID that you've made push notification active for. This way when you develop it will have the push notification function built in.

I don't know if you can enable that for a wildcard app, but after trying at least 12 different suggestions and losing a few days I hope this helps someone

Taryn
  • 242,637
  • 56
  • 362
  • 405
  • 2
    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. – matt Nov 29 '12 at 23:08
  • 1
    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 Feb 14 '14 at 16:11
4

You mention a provisioning profile but I don't see any mention of an Apple Push Profile.

To use Push you must have a push profile (there are two, one for development and one for release). After you've created it you'll need to make sure it contains the relevant certificates (see the EDIT section below).

This is an excellent tutorial that will walk you through all the steps:

http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12

It would take me, or anybody else, hours and hours to write a thorough detailed answer like this tutorial, so I'm not going to attempt to, nor lay claim to the bounty when this tutorial already exists.

P.S. I believe you don't need entitlements any more, this is a legacy thing.

EDIT: You should also check you have the necessary profiles on the device - go to the settings, then general, profiles, check your profiles are listed, especially the push profile of course. You can also check this from the Organizer section of XCode. In Organizer there are two sections that say Provision Profiles - one at the top left in Library (this is the profiles in XCode that you use to sign etc.) Also you will see a section call Provisioning Profiles for the device that is connected, this is the profile that is installed on the handset. If you don't have them installed on the handset you can download them from the provisioning portal website, then click on the Add button at the bottom of the Organizer window.

While in the provisioning portal you should also check that the Apple Push Profile includes the certificates: - click on Provisioning on the left hand menu - you'll see a list of your profile, select to EDIT the Apple push profile - you'll see a certificates section, with a list of developers or testers etc. you have in your project, make sure the check box is checked for them. - you'll also see a devices section, make sure the device you are testing on has been added.

If you have any old profiles in XCode or on the device delete them and download/refresh/install all the new profiles from the provisioning portal

Gruntcakes
  • 37,738
  • 44
  • 184
  • 378
  • 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 Jun 14 '12 at 14:06
  • Also, I've added some info about the actual mobileprovision file which could be useful. – jwl Jun 14 '12 at 14:12
  • 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. – X Slash Jun 14 '12 at 14:17
  • 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 Jun 14 '12 at 15:11
  • I've updated the answer with some more things for you to check. – Gruntcakes Jun 14 '12 at 23:13
2

Ran into this same issue myself. For me, the issue was that my product name ($TARGET_NAME) was not capitalized the same way presented in the certificate provided by apple. For example, i had com.companyid.APNDemo whereas the Apple cert was using com.companyid.apndemo.

I changed my target to be lowercase and it worked. Note: The clue for me was the codesigning setting in Build Settings was set to my default developer certificate; not the APNTest provisioning profile.

David Carrico
  • 421
  • 1
  • 4
  • 13
1

A lot of the above answers are correct. However, there seems to be more than one possible error when dealing with this.

The one I had was a capitalization issue with my App ID. My App ID for some reason wasn't capitalized but my app was. Once I recreated the App ID with correct capitalization, it all worked smoothly. Hope this helps. Frustrating as hell though.

P.S. if it still doesn't work, try editing the Code Signing Identity Field manually with "edit". Change the second line with the name of the correct provisioning profile name.

matrinox
  • 472
  • 5
  • 8
1

It took me hours to solve it. Given that someone is using custom scripts to sign and pack while others are using xcode itself, there's only one way to check what ended in your app. Dump you entitlements with

codesign --display --entitlements :- path/to/MyApp.app

and check aps-environment and application-identifier.

dwery
  • 1,128
  • 10
  • 20
  • i have been facing the same problem. Just wanted to ask, does the path-to-app is for app installed on simulator? – Ajeet Sep 05 '14 at 11:18
  • no, it's the path of the compiled app for the actual device, in the xcode build directory. – dwery Nov 09 '14 at 20:27
1

This error may occur when your certificate has expired.

The solution is to renew certificate and sign the application with it.

vahotm
  • 379
  • 5
  • 16
1

You need to make sure you have in your provisioning profiles (https://developer.apple.com/account/ios/profile/) an iOS Distribution profile.

When you upload from xCode to the App Store, make sure you have the aps-environment in the entitlements. If not, download them from the View Accounts -> View Details -> Download All.

Nathan B
  • 1,625
  • 1
  • 17
  • 15
1

I had a similar issue. I've been bouncing between XCode 7 and 8 for a variety of reasons. Once you use 8 to build, you will need to use 8. I simply used Xcode 8 and applied some of the changes suggested above and it worked.

1

recreating provisional files fixed my all problems.

Faris Muhammed
  • 970
  • 13
  • 17
0

There seem to be something quirky with the 'automatic' entitlements in Xcode 4.6.

There is an Entitlement.plist file for each SDK at:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/Entitlements.plist

A workaround solution I came up with was to edit this file and add the sneaky aps-environment key manually like so:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>application-identifier</key>
    <string>$(AppIdentifierPrefix)$(CFBundleIdentifier)</string>
    <key>aps-environment</key>
    <string>development</string>
    <key>keychain-access-groups</key>
    <array>
        <string>$(AppIdentifierPrefix)$(CFBundleIdentifier)</string>
    </array>
</dict>
</plist>

Then, Xcode is generating correct Xcent file, which contains the aps-environment key at:

/Users/mySelf/Library/Developer/Xcode/DerivedData/myApp-buauvgusocvjyjcwdtpewdzycfmc/Build/Intermediates/myApp.build/Debug-iphoneos/myApp.build/myApp.xcent

You can locate where your Xcent file is created using Xcode's Log Navigator,
look for "ProcessProductPackaging".

Unfortunately, this is the only way I found that fixes the issue.
(and finally able to properly get push token now)

Just wondering if another more elegant solution is available.
Please see my SO question for more details on that:
Xcode 4.6 automatic entitlement not working - "no valid aps-environment"

Community
  • 1
  • 1
AmitP
  • 5,353
  • 4
  • 35
  • 27
0

Before deleting and regenerating AppIDs/Profiles, make sure your Library and Device have the same (and correct) profiles installed.

I started seeing this error after migrating to a new computer. Push had been working correctly prior to the migration.

The problem was (duh) that I hadn't imported the profiles to the Xcode library on the new machine (in Organizer/Devices under Library->Provisioning Profiles).

The confusing part was that the DEVICE already had the right profiles and they showed up as expected in build settings, so everything looked correct there, but the XCode LIBRARY didn't have them, so it was signing the app with...???

0

This was what fixed it for me. (I had already tried toggling the capabilities on/off, recreating the provisioning profile, etc).

In the Build Settings tab, in Code Signing Entitlements, my .entitlements file wasn't link for all sections. Once I added it to the Any SDK section, the error was resolved.

enter image description here

mogile_oli
  • 2,148
  • 2
  • 21
  • 21
0

I tried out all the answers listed here but no one solved my issue. In my case this error is due to my silly mistake in Appid creation. I used Wildcard App ID instead of using Explicit App ID caused the problem

If you want an application to receive remote notifications(push notification), then you need to use an Explicit App ID, such as com.tutsplus.push, instead of com.tutsplus.*

Please find the ScreenShot, enter image description here

arunjos007
  • 4,105
  • 1
  • 28
  • 43
0

enter image description hereAll you need to do is, add one key in .Entitlements File.

APS Environment this key needs to be added and value should be Developement or Production as per your purpose .

Kindly check uploaded image

PoojaArora
  • 31
  • 3