How to fix “no valid 'aps-environment' ent

2019-01-05 08:21发布

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.

23条回答
再贱就再见
2楼-- · 2019-01-05 09:05

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

查看更多
欢心
3楼-- · 2019-01-05 09:07

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.

查看更多
4楼-- · 2019-01-05 09:07

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.

查看更多
Summer. ? 凉城
5楼-- · 2019-01-05 09:08

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.

查看更多
唯我独甜
6楼-- · 2019-01-05 09:09

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.

查看更多
一夜七次
7楼-- · 2019-01-05 09:11

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.

查看更多
登录 后发表回答