apple-push-notificationsdevicetoken

Determine if device token is sandbox or distribution


Is there a way to determine if a device token is sandbox or distribution? We are testing and the application is sometimes signed with a development certificate and others are signed with an ad hoc certificate(distribution certificate). This is because we are passing the application around to some of the 100 provided ad hoc test devices, and also building development signed apps to our devices. Because sending a push notification requires that we select the appropriate push server and pem file, it would be great to be able to determine if the token is sandbox or distribution to send the notifications in the appropriate way so that the push notification succeeds. We must sometimes use the distribution profile to sign our applications, so testing the push notification system requires us to deliver these notifications properly.


Solution

    1. Open project build setting
    2. Go to preprocessing settings
    3. Under "Preprocessor macros not used in precompiled headers" (assuming you are not branching code in a .pch file), add TOKEN_ENV_SANDBOX=0 under Release and TOKEN_ENV_SANDBOX=1 under Debug and Ad Hoc.
    4. In your code wherever just use the compiler directive

    #if !TOKEN_ENV_SANDBOX
    NSLog(@"TOKEN_ENV==PRODUCTION");
    #endif

    #if TOKEN_ENV_SANDBOX
    NSLog(@"TOKEN_ENV==SANDBOX");
    #endif

    EDIT: Corrected an issue above.