Determine whether app is communicating with APNS sandbox or production environment

Posted by goldierox on Stack Overflow See other posts from Stack Overflow or by goldierox
Published on 2012-04-13T19:12:02Z Indexed on 2012/04/13 23:29 UTC
Read the original article Hit count: 214

Filed under:
|
|

I have push notifications set up in my app. I'm trying to determine whether the device token I've received from APNS in the application:didRegisterForRemoteNotificationsWithDeviceToken: method came from the sandbox or development environment. If I can distinguish which environment initialized the token, I'll be able to tell my server to which environment to send the push notification.

I've tried using the DEBUG macro to determine this, but I've seen some strange behavior with this and don't trust it to be 100% correct.

#ifdef DEBUG
BOOL isProd = YES;
#else
BOOL isProd = NO;
#endif

Ideally, I'd be able to examine the aps-environment entitlement (value is Development or Production) in code, but I'm not sure if this is even possible.

What's the proper way to determine whether your app is communicating with the APNS sandbox or production environments? I'm assuming that the server needs to know this in the first place. Please correct me if this is assumption is incorrect.

Edited: Apple's documentation on Provider Communication with APNS details the difference between communicating with the sandbox and production. However, the documentation doesn't give information on how to be consistent with registering the token (from the iOS client app) and communicating with the server.

© Stack Overflow or respective owner

Related posts about ios

Related posts about push-notification