System should tell us which APNs environment we are in

Originator:ben.dolman
Number:rdar://19605314 Date Originated:26-Jan-2015 03:43 PM
Status:Open Resolved:
Product:iOS SDK Product Version:
Classification: Reproducible:
 
Summary:
When a server sends a push notification it needs to know whether to send it to the production or sandbox environment. That information is not a part of the device token so when the app sends the token to its server it needs to tell it which environment the token is for.

Instead of making the app try to figure this out in a roundabout way I propose that this is added as an extra parameter to -[UIApplicationDelegate application: didRegisterForRemoteNotificationsWithDeviceToken:]

Something like this:

[UIApplicationDelegate application: didRegisterForRemoteNotificationsWithDeviceToken:environment:]

and on OS X:

[NSApplicationDelegate application:didRegisterForRemoteNotificationsWithDeviceToken:environment:]

This seems logical to me because the system already has to determine whether it's sandbox or not in order to generate the proper token type. Why not just pass that information on to the app along with the token?

Right now the options for figuring out which environment you are in are not great:

1. The most popular the build configuration using a preprocessor variable. E.g. When using the "Debug" configuration, set a constant at build time that says that it's the sandbox environment.

Problems: First, the APNs environment is not determined by build configuration—it's determined by the certificate/provisioning profile. It's completely valid to use a "Debug" build configuration but sign the app with a Distribution cert/profile. We do this for our internal, continuous-deployment builds on the old TestFlight.

2. At build time determine if the signing certificate is a development or a distribution certificate by looking at the certificate name.

Problems: Depending on certificate names seems fragile. And cert names are not completely consistent across iOS and OS X. "iPhone Developer" "iPhone Distribution" "Mac Developer" "3rd Party Mac Developer Application". Also, doing this at build time is a problem if you re-sign your application with a different certificate later.

3. Read the embedded provisioning profile at run time and look at the "aps-environment" value.

This is actually the most reliable way, but still not great. It requires you to embed an ASN.1 parser or to rely on a hacky way of reading out the plist data from the signed payload.

Steps to Reproduce:
1. Register for remote notifications ([UIApplication 
registerForRemoteNotifications]
2. Receive a token in [UIApplicationDelegate application: didRegisterForRemoteNotificationsWithDeviceToken:]
3. Try to divine whether this is a sandbox or production token
4. Send the token to your server along with the environment information.

Expected Results:
The system would tell me which environment the device token is in.

Actual Results:
I have to do some crazy stuff to figure it out on my own.

Version:
iOS 8

Notes:


Configuration:
iOS

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!