iOS: Production push notifications, Invalid token from APNS server

后端 未结 6 1096
死守一世寂寞
死守一世寂寞 2020-12-09 10:10

My app is now available in the app store, so I\'ve downloaded it to my device. The push notifications were working fine during development. I am using JavaPNS to send out th

相关标签:
6条回答
  • 2020-12-09 10:34

    MyApp is an iOS app that sends and receives Push Notifications MyApp-to-MyApp using APN token IDs fetched from a database that is kept updated by each MyApp at logon. The Push Notifications are sent by MyApp using the NWPusher framework API.

    As long as the project was run in Developer (Debug) mode, sent and received Push Notifications worked perfectly. But, in Production mode, sending Push Notifications would not work.

    I went back and completely recreated my AppID, SSL certificates, provisions, etc., but to no avail. Next I used the NWPusher MacOS Pusher app to experiment with sending Push Notifications to MyApp. I configured Pusher to send a Push Notification (to the tokenID of an Ad Hoc distribution of MyApp) with MyApp’s Production SSL certificate, and got the following message in the Pusher log: "Notification error: APN invalid token".

    I next noticed that Pusher had a checkbox option “Should use sandbox environment” checked. I unchecked the option and tried it again. This time the Push Notification was sent and then received by the target phone without any errors. This led me to take another look at the NWPusher.connect call:

    Swift:

                let pusher:NWPusher? = try? NWPusher.connect(withPKCS12Data: pkcs12! as Data, password:APNS_Certificate_Password,environment:NWEnvironment(rawValue:1)!)
    

    which has an environment argument NWEnvironment enum with possible values 0=none, 1=sandbox, 2=production, 3=auto.

    Changing rawValue:1 (develop sandbox) to rawValue:2 (production) fixed the problem: Production Push Notifications now work without errors.

    0 讨论(0)
  • 2020-12-09 10:34

    Found the root cause for this issue, it is because of bad private key. To resolve this issue just generate a .p12 certificate with .pem . For creating the p12 file with .pem file please follow the below method

    0 讨论(0)
  • 2020-12-09 10:39

    xCode 8.0

    I had "invalid token" error the after installing of xCode 8.0. The issue was found here: Project Navigator -> select project (topmost item) -> select project name in Targets menu -> choose Capabilities in top menu -> look at PUSH Notifications section -> click "Fix issue"

    0 讨论(0)
  • 2020-12-09 10:41

    Under ios App Bundle IDs menu in https://developer.apple.com/account/ios/identifier/bundle

    click the id of your app if in production, add a new certificate if the old one has expired.

    Ensure your App Bundle ID com.myapp.mycom matches your Certificate Name com.myapp.mycom

    0 讨论(0)
  • 2020-12-09 10:51

    The device token for production is different than the development one, so if you send a development token to production APNS servers (or vica versa), that's the cause of the problem.

    It's possible you didn't remove the development device token from your server when you switched to production.

    Or if you are getting the development token from your production app, then either the app is returning a locally stored device token (which you may have stored on your device during development) instead of asking Apple to get a new one, or (if you do ask Apple for a current token and still get the development token) your app is not signed with the production provisioning profile.

    0 讨论(0)
  • 2020-12-09 10:52

    I re-downloaded the push production certificate and exported it from the keychain as .p12. This seems to have solved the problem. It seems strange though that a bad private key was giving me the "Invalid Token" error.

    0 讨论(0)
提交回复
热议问题