2
votes

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

2
Why is this a problem for your app? Are you not supporting multiple tokens per user? - Jonah
multiple tokens per user? pardon? for sending push notification token is only one per user. - Bhavesh Lathigara
Only one token per user? What about users with multiple devices (a phone and tablet), or users who upgrade to a new device, are you sure you only want to store one token? - Jonah
Mate, this is not regarding my question will you please read below comments? - Bhavesh Lathigara

2 Answers

4
votes

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.

3
votes

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.