Reputation: 163
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!
Upvotes: 8
Views: 4860
Reputation: 6262
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.
Upvotes: 7