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!
'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. '
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.
No, Device token will always be same .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With