How to separate tokens from a sandbox and a product iOS APNS notification device

I'm not careful and mix markers from sandbox and production device in the same db table. This causes some devices that install the production application to not receive push notifications.

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

+6
source share
1 answer

You should probably enter the database table with some UDID (you can create your own by hashing the packet identifier 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 may be the actual token.

In delegate deletion in the didRegisterForRemoteNotificationsWithDeviceToken delegation method, you can add logic to determine if your application is in development or production mode and updates your database using the device token based on the UDID and the “mode” in which the application operates in.

Your code might look something like this:

- (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 for me CONFIGURATION_AdHoc, CONFIGURATION_Debug, CONFIGURATION_Distribution and CONFIGURATION_Release.

+6
source

Source: https://habr.com/ru/post/926486/


All Articles