{ by david linsin }

July 06, 2010

Push Notifications in Production

Last year, I worked on a Nine Men's Morris (Mühle) implementation for Android, called Doublemill. Since I'm an iPhone user, I decided to port the game to iPhone/iPod touch and the iPad. There are 3 versions: Doublemill Premium, Doublemill Lite and Doublemill for iPad.

In a previous blog post I highlighted a couple of gotchas you need to be aware of when implementing Apple Push Notifications. Unfortunately, I didn't really pay attention to one of them myself:

The first problem I ran into, had to do with my provisioning profile for development. I enabled APN in my Provisioning Portal, installed the certificate and implemented all the delegate methods according to the documentation, but somehow the method

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error


was called with error code 3000 - "no valid 'aps-environment' entitlement string found for application". I was pretty sure, I setup everything correctly. However, I missed one little thing:

After you have generated your Client SSL certificate, create a new provisioning profile containing the App ID you wish to use for notifications.


This bit me after submitting Doublemill Premium to the App Store and being rejected for promoting Push Notifications in my App description, but according to Apple, not implementing it. During beta testing, everything worked fine. I had a correct implementation and the App was asking me for permission to use Push Notifications.

However, I did forget to create a new distribution provisioning profile for the App Store, after enabling Push Notifications for production. So, it didn't work for the reviewer at Apple. Forgetting about something like this is very painful, especially since I'm waiting for the 3rd round of review for the next release of Doublemill. That makes it 3 weeks since the initial submission.

When asking about this on the Apple Developer Forums, Mike was so kind to point out a neat trick on the command line, which helps you identify, whether APN for production is enabled:

codesign -dvvvv --entitlements - /path/to/App

<key>aps-environment</key>
<string>production</string>


If you see aps-environment=production, you should be save. Push notifications should work. If the key is missing, then you should create a new provisioning profile and rebuild you App with that.

It would be nice if Apple built this kind of checks into XCode or at least invalidate the provisioning profiles as soon as you enable Push Notifications in your App ID.

5 comments:

Anonymous said...

I had the same problem, I noticed push not working after the app was on AppStore. completely pissed my off. Maybe it's best practice to enabling push as soon as you make an App ID.

Anonymous said...

Thank u so much, i rechecked and created a new Distribution profile. Also, i forgot to change from " ssl://gateway.sandbox.push.apple.com:2195'" to " ssl://gateway.push.apple.com:2195'"

Sandeep Arneja said...

thanks. this was so helpful. also another way of checking for the entitlements would be to open the provisioning profile in a text editor and to search for the key aps-environment. thx -Sandeep

Bil Repenning said...

I have a related but different question. I have not gone to the app store yet. My problem is still when using the sandbox: My developer profile works fine - all notifications received. However when I try to use my Enterprise Distribution profile so I can send to beta testers I get an invalid token repsons form APNS. I noticed that no matter what I do any archive build has an aps-environment of "production". Do you know if this is expected? Is there no way to make an archive that has an aps-environment value of "development" (such as a debug build would have)? The theory I'm working off of now is that if you want to test push on the sandbox you can not archive because archives re always forced to "production". Thanks for the help!

safdar said...

Nice post. Thanks for sharing.


com_channels

  • mail(dlinsin@gmail.com)
  • jabber(dlinsin@gmail.com)
  • skype(dlinsin)

recent_postings

loading...