2

I'm currently creating an app that needs to receive push notifications from a server.

When I got the device token, I send it to my server and save it into DB,

My question is:


When I tried to normally install application on device from XCode, I got the correct device token and it is working for push notification.

But when I tried to install application from TestFlight or diawi, device tocken changed and for that wrong device tocken application not receive any push notification.

any help will be appreciate

Bhavesh Lathigara
  • 1,355
  • 1
  • 15
  • 25

2 Answers2

4

I found answered of my question.

Never use your NSUserDefaults' key as @"key".

For example what I have previously used.

[[NSUserDefaults standardUserDefaults] setObject:deviceToken forKey:@"key"];
[[NSUserDefaults standardUserDefaults] synchronize];

And what I am using now.

[[NSUserDefaults standardUserDefaults] setObject:deviceToken forKey:@"token"];
[[NSUserDefaults standardUserDefaults] synchronize];

And now push notification is coming as it is.

So conclusion is never used your key name @"key". I don't know why but may be some preference is using this @"key" by default.

Thanks.

Bhavesh Lathigara
  • 1,355
  • 1
  • 15
  • 25
  • 1
    Glad to see you sorted this one out. It would have been impossible to guess "from the outside" :) – Rok Jarc May 28 '15 at 08:00
3

When you install your app on the device via XCode it will run in development (sandbox) configuration. You will receive development token and you need to issue push notification via ssl://gateway.sandbox.push.apple.com:2195 (using development certificate).

However: when you install your app via TestFlight your app is compiled (an run) in distribution (production) mode: production token is not the same as development token. It is also not enough to simply use this new (production) token. Push notification has to be issued via ssl://gateway.push.apple.com:2195 (using production certificate) in this case.

Rok Jarc
  • 18,765
  • 9
  • 69
  • 124
  • Thanks for reply, as per your answer no worry for device tocken but in sandbox mode app able to receive push notification but in distribution mode (TestFlight) app not able to receive push notification. And I made .pem file clearly from distribution.p12 file so there is no doubt about that. and yes confusion is in iOS 7.1.2 push notification is coming. so after all issue is in device token. – Bhavesh Lathigara May 26 '15 at 05:53
  • Are you also using distribution URL (gateway.push.apple.com) instead of the sandbox URL (gateway.sandbox.push.apple.com) when testing in distribution mode? I would check and re-check the certificates and server URL-s. [Here](http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1) you can find a simple script (simplepush.php) that allows you to quickly test everything locally. – Rok Jarc May 26 '15 at 06:43
  • yes I have already done that, but my friend my question is not about sandbox or distribution that I already knew and done but my question is device token will change and given something wrong if we install app via diawi or TestFlight so that I am not able to get push notification. no matter if I make ipa in development or distribution, I got this issue in both mode. – Bhavesh Lathigara May 26 '15 at 12:52
  • Aha, sorry for misunderstanding. The way we deal with this is that we hold special table (in database) with device_identifier, production_token and development_token. Each time app launches it requests apps_token and sends it to the server (together with device_identifier). This way we always have only the latest (thus valid) token(s) for each device. – Rok Jarc May 26 '15 at 13:23
  • Yes I am doing same way and of course device token also updated correctly but some how device token is not for that particular device and php server code not able to identify the device and it is not sending push notification to that particular device that is my problem. – Bhavesh Lathigara May 26 '15 at 14:40