0

When I start the app, it registers for push notifications and depending on the provisioning profile it will generate a different push token.

Since both AdHoc and AppStore provisioning profiles connect to the same server, I have to somehow distinguish what kind of token it is, so that the server can connect to the right apple server. (sandbox/production)

How can achieve that?

sigma
  • 117
  • 7

1 Answers1

1

I believe the best way to achieve this would be to make the development/production distinction when you send the token to the server, and have your server annotate the type of token in the database.

Surely you have some sort of API call to your server which is passing in the token. In that call, pass in the type of token as well. Ex:

{ "token" : "abcd....", "type" : "development" }

To actually make the distinction at build time, you can use preprocessor directives to detect whether it's a debug build, release build, or an App Store build.

Checking if debug is enabled is easy, but to make a distinction about whether it's AdHoc or App Store, consider creating a user defined variable. To do this, clone the Release scheme and create one called App Store. Then in your Build Settings, go to user defined variables and create one called APP_STORE, but only for the App Store scheme. When you release to the store, make sure that you build using that scheme instead of Release when you archive.

Then, checking the type to pass into your API is as easy as doing this:

NSString *type = nil;
#ifdef DEBUG
    type = @"debug";
#elseif APP_STORE
    type = @"app_store";
#else
    type = @"release";
#endif
Aaron Wojnowski
  • 6,352
  • 5
  • 29
  • 46
  • Yes, that's what we are doing right now, even with different servers for the two modes. But somehow for distribution the apple services return "invalid token", so I wanted to check the development/distribution flag programatically and send it to the server just to be sure. – sigma Apr 25 '15 at 23:50
  • Can you please share your IFDEFs? What was proposed should work. – Dan Apr 27 '15 at 01:27
  • After lots of testing we found out the provisioning profiles were "invalid" (yellow sign in the member center). After recreating those, all went fine. APN tokens generated, server was able to send a push, etc. Sorry for the confusion and thx! – sigma Apr 27 '15 at 20:24