Using sandbox APNS on AdHoc Distribution Builds for iOS - iphone

I've been reading a bunch of Apple's docs, as well as many other SO questions, but haven't found the answer to this particular question.
I have an existing workflow in place for generating AdHoc Distribution builds for QA members and beta testers. Now that I've added support for push notifications, I'd like those notification paths to be able to be tested as well.
I'm under the impression that Developer builds, signed with a Development provisioning profile, generate tokens that for the sandbox/development APNS environment, and Distribution builds, signed with a Distribution provisioning profile (whether that be destined for AdHoc Distribution OR AppStore Distribution), generate tokens for the production APNS environment. I believe this can be confirmed by opening the different .mobileprovision files, and examining the aps-environment key.
I'd like to know if there's a way to have my AdHoc Distribution builds use the sandbox APNS environment, rather than the production APNS environment.
If I really wanted QA and beta testers to use sandbox APNS, would I have to somehow find a way to allow them to run development builds, rather than distribution builds?
Or are my assumptions about the way things work way off base? (referenced this post and this post)

I did found some mention to AdHoc in the context of APNS environments :
Note: There is a separate persistent connection to the push service
for each environment. The operating system establishes a persistent
connection to the sandbox environment for development builds; ad hoc
and distribution builds connect to the production environment.
It's taken from Technical Note TN2265.
I guess this note confirms that you can't use the sandbox env in AdHoc distribution.

Apple uses a different server for:
Apps signed with a Development profile
All other profiles (AdHoc, InHouse and AppStore). These are going via a Live Server.

Related

Sandboxed APNS environment & .mobileprovision file

Anyone know the details of .mobileprovision file? I have an app which I want to point to sandbox APNS environment, I believe I need to create a .mobileprovision file for sandbox environment. Do all the devices which will use my distribution build needs to install some provision profile in order to receive the Pushes from sandbox APNS environment?
You need to have a separate development and distribution certificate for you push server as well as signing the app with different development and distribution certificates that are associated with an appID that has push notifications enabled.
Note that if you are testing (Ad Hoc) then you also need a distribution certificate specifically for ad hoc distribution (you can generate this from you apple developer site).
Finally, this guide helped me create the certificates I needed for my push server.
http://code.google.com/p/apns-php/wiki/CertificateCreation
Also, here is the apple developer page talking specifically about the different certificates required for sandbox and distribution builds for push notifications:
https://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ProvisioningDevelopment/ProvisioningDevelopment.html

Provisioning Profiles + Push Notifications + Production vs Development

I'm building an iOS app that uses push notifications, and I'm finally ready to submit it. Before I do, I'd like to test out push notifications off the Production server, to make sure everything is working correctly. Thus far, the sandbox environment has been working fine.
After doing quite a bit of searching, I learned that switching the servers over from ssl://gateway.sandbox.push.apple.com:2195 to ssl://gateway.push.apple.com:2195 wasn't enough, and that production push tokens are different from sandbox push tokens. Instead, apparently I need a new provisioning profile with Production entitlements, new certs installed on my server, and to re-build my app with said profile so that it knows to create the correct push tokens.
So, after going through all the steps, I can't even make a build run on my phone; XCode says
This profile cannot be installed on devices
Here are the steps I've taken. If I'm missing something please let me know:
In my iOS Developer Center, I've made sure that my AppID is "enabled for production" under the Apple Push Notification Service.
Also in my iOS Developer Center, I've created my Production Push SSL Certificate, gone through the necessary conversion steps, and installed the resulting .pem on my server.
Per the instructions, I've create "a new provisioning profile containing the App ID you wish to use for notifications." I've done this by going to Provisioning, and clicking on the "Distribution" tab, and making a new profile. I've confirmed that "production" is set under the "entitlements" section of this profile.
I've selected the provisioning profile in my project settings. I get the message
This profile cannot be installed on devices
and I'm stuck.
Build an ad-hoc distribution version of your app, and install it on your own device. That will use the production APN gateway and certs.
You cannot install an app compiled with a appstore distribution (production) profile on a device. Only Apple reviewers can do that. you can only test push on an app compiled in development mode and using sandbox server.
If you want to test production servers, you must compile the app using an AdHoc distribution profile enabling the devices you want to do the test. Clearly you must recompile and the send the app for review using the App Store distribution profile.

Team Agents the only ones that can build Ad Hoc?

First a little background. I am building a mobile app for a client, this client currently owns the developer account they wish to distribute the application from. Previously, I had been using my own developer account to build ad hoc to send milestone builds to the client. We are now getting close to ship and I have begun transferring the build to using the client's credentials.
Honestly, this is the first time I've worked on an app that was in my own developer account, so even setting up the dev cert/provisioning took some trouble shooting. Specifically, I couldn't use their existing developer certificate, but one that I created on my machine, uploaded and they approved. That's fine, I'm building locally to my device now.
However, (and here's my question) I ran into problems setting it up for them to do ad hoc distributions. Namely, installing their ad hoc certificate doesn't seem to work. My assumption is that it is because it wasn't build on my machine. However, there is no facility as a non-team agent to create my own Ad Hoc certificate.
Is it the case that only team agents can do Ad Hoc (and I'm assuming submission builds) from their machine? Is there no way that I as a Team Member can do an ad hoc build from my development machine?
When you generate a signing request in Keychain Utility (the first step of generating an Ad Hoc profile), it simultaneous generates a private key and saves it to your keychain. You can only build against the Ad Hoc provisioning profile if you have that private key in the Keychain on your Mac.
So your solutions are
Get them to export their private key from the keychain and send it to you. You then import it into your keychain. They should also send you the Ad Hoc mobileprovisioning file they created. You drag and drop this onto xcode.
Generate the signing request on your machine, and send it to them to generate a new Ad Hoc profile which will then only work on your Mac (though again, you could send them the private key).
The final option would be to send the source code to them to compile the Ad Hoc builds.
The Provisioning Portal Distribution How-To explicitly states:
Only Team Agents are authorized to
prepare and submit applications for
distribution.
Team Agents are also the only ones authorized to create an Ad-Hoc distribution profile.
However, once the distribution profile is created, the Team Agent should be able to download it and hand it off to you for creating Ad-Hoc distribution builds.

Why not use development provisioning instead of ad hoc?

I was under the impression that when you use a development provisioning profile for a build of an app, only the specified developers can deploy that build to a phone.
But I just deployed a build that uses a development profile to a phone using Xcode Organizer, even though I'm not one of the valid developers for that profile. One of my colleagues, who doesn't even have Xcode installed, did the same with his phone using iTunes.
In that case, why not use a development provisioning profile for distributing your app to e.g. your QA team, instead of ad hoc distribution?
EDIT: Please read the part in bold carefully before answering. I'm not asking a basic "how does this work" question. I've made a lot of development, ad hoc, and app store builds, and now I find that I seem to have made some wrong assumptions.
There's one situation in which you need an Ad Hoc profile, and that's when you want to test Push Notifications.
If you test Push Notifications on a Development Provisioning Profile, your push notifications need to be sent using the Development Push Notification Certificate for your SSL connections to Apple's sandbox APNS server.
If you want to test Push Notifications using your Production Push Notification Certificate and the live APNS servers, you'll have to deploy your app to a device using a Distribution Certificate and Ad Hoc Provisioning Profile (which includes doing the Entitlement.plist steps, which you can ordinarily skip if you were only using Developer Provisioning Profiles).
Also note that when you deploy using an Ad Hoc profile, your device token will be different from the one you use when you're using the development profile. This the recommended way to test APN because there's no back end changes that need to be made between the Ad Hoc build and the final live deployment on the AppStore.
Ad-Hoc is not for developers, but for testers. Who do not have iPhone SDK / XCode, iTunes only.
(The answer is: you can install ad-hoc app without developer certificate, and can't do it with development app)
Method 1: Install from XCode
The Development Provisioning Profile requires you to run the app (initially) from within XCode.
This has the side-effect of marking the device as being used for development, but also requires you to connect the iPhone/iPod Touch to the machine running XCode. Once you run the app from XCode, the app is installed on the device and you no longer need to be connected to the machine to run it. (Until you want to update the app.)
Method 2: Install from iTunes
An Ad-Hoc provisioning profile allows you to give the app to anyone and let them install it themselves using iTunes. You send them:
the app, and
the Ad-Hoc Provisioning Profile
They select these two and drag them onto iTunes. Then sync.
Later, you can give them an updated version of the app only (without the Ad-Hoc Provisioning Profile, since they've already installed that on their device) and they can drag the new app onto the iTunes icon to install the new version.
One limitation to Ad-Hoc distribution, is that it requires you to enter each Device ID into the iPhone Development Portal. And there is a limit to 100 device IDs per year (you cannot erase any IDs, until your next year begins -- only add them). The 100-ID limit will not be a hindrance for most developers, just keep in mind that you need to get the device ID ahead of time, before you create the Ad-Hoc Provisioning Profile to send to the person you want to install your app.

Push-Notification works on develpoment but not on production

So we have a problem with our app. We put push-notification in, and it works flawlessly in development. Then, once we got on the app store push no longer works. By looking at our server logs it looks like the the registration call is failing and not getting a device token.
Has anyone encountered this before?
Cheers,
Did you create a production push notification SSL certificate? This is most frequently the cause. Applications signed with a development provisioning profile will not work with a production push SSL cert and applications signed with a distribution provisioning profile will not work with a development push cert.
Also, you can create an ad-hoc distribution cert and use this to test your distribution provisioning profile. Since you can't run the build you send to Apple for distribution, I'd strongly encourage you to make an ad-hoc distribution build and confirm that push notifications work in that installation.