Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to separate sandbox and production device token of iOS APNS notification

I am not careful and mix sandbox and production device tokens in the same db table. It leads to some devices which install production app can't receive push notification.

How to separate sandbox tokens and production tokens from db table? Your help is highly appreciated!! Thanks!

like image 592
Tomson Avatar asked Sep 28 '12 09:09

Tomson


People also ask

What is device token in Apple Push Notification?

'The device token you provide to the server is analogous to a phone number; it contains information that enables APNs to locate the device on which your client app is installed. APNs also uses it to authenticate the routing of a notification. '

Is device token unique in iOS?

A device token is an identifier for the Apple Push Notification System for iOS devices. Apple assigns a Device Token on a per-app basis (iOS 7 and later) which is used as a unique identifier for sending push notifications.

Do device tokens change iOS?

No, Device token will always be same .


1 Answers

You should probably be keying your database table with some sort of UDID (you can create your own by hashing the bundle ID and the MAC address of the device) AND a second field that indicates whether the token is a "development" or a "production" token. The third field can be the actual token.

In your app delegate in the didRegisterForRemoteNotificationsWithDeviceToken delegate method you can add logic to determine whether your app is running in development vs. production mode and update your database with the device token based on the UDID and the "mode" the app is running in.

Your code might look something like the following:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken 
{
// Update the device token record in our database
#if !defined (CONFIGURATION_Distribution)
   // Update the database with our development device token
#endif

#if defined (CONFIGURATION_Distribution)
   // Update the database with our production device token
#endif
}

To do this you need to go to your Project -> Build Settings. In the Preprocessor Macros section type CONFIGURATION_ and press Enter. This should create a preprocessor macro for each of your build configurations. In this case my build configurations are AdHoc, Debug, Distribution, and Release.

It creates CONFIGURATION_AdHoc, CONFIGURATION_Debug, CONFIGURATION_Distribution, and CONFIGURATION_Release for me.

like image 137
radesix Avatar answered Nov 13 '22 22:11

radesix