Device Tocken will Change after install from diawi or TestFlight? So Push notification is not coming

萝らか妹 提交于 2019-12-03 15:17:48

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/30444851/device-tocken-will-change-after-install-from-diawi-or-testflight-so-push-notifi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!