1

Im trying to send VoIP notifications via PushKit, but in Production(Distribution) environment, I get "Invalid Token" from server.

everything works fine in development env with same certificate and url:ssl://gateway.sandbox.push.apple.com with port:2195 but when i change the url to:ssl://gateway.push.apple.com, I get "Invalid Token" error with no extra data

Arkhan
  • 56
  • 6
  • check your p12 file is it for development or distribution – Abhishek Thapliyal Jul 01 '17 at 12:03
  • @AbhishekThapliyal There is just one type of certificate for `VoIP Services Certificate` and the certificate should work for both envs. – Arkhan Jul 01 '17 at 12:21
  • Please check again as apple have this distribution and development certificates even normal APNS have two type distribution and development – Abhishek Thapliyal Jul 01 '17 at 15:30
  • @AbhishekThapliyal In `developer.apple.com`, in `Certificates, Identifiers & Profiles` section, when I try to add a new certificate, there is only one option in "Production" section for VoIP Services `VoIP Services Certificate: Establish connectivity between your notification server, the Apple Push Notification service sandbox, and production environment to alert background VoIP apps of incoming activity. A separate certificate is required for each app you distribute.` – Arkhan Jul 02 '17 at 05:12

1 Answers1

0

Looks like you are using same Voip device token generated by Client in sandbox environment for both sandbox as well as production. That's the reason you will get invalid token error.

This will not work. If you want to use production environment, you need to make sure your client/app is creating device token in production environment. (You can not use device token generated by client using Sandbox when your server is using production environment)

Pl. note separate device tokens are generated for sandbox/production environment for the same app/client on the same device. Hope it helps.

Ayush
  • 390
  • 3
  • 11
  • Thanks for your answer, but I'm already using production token in production env, I've also figured some weird behavior, for some tokens I don't get this Invalid Token error. i tried sending push to three different devices (to their production tokens, all installed from testFlight ), for two of them Im getting the error, but for another one it is successful! – Arkhan Jul 04 '17 at 08:42
  • Invalid Token error is returned by production APNS only if that token is not allocated to any device by that production Server. If you're sure that Client app has requested this device token using production APNS only, Then APNS shall be able to route notification for this destination.This is weird. Must not happen. What you're saying is if true, looks like to be some device token sync issue at APNS servers (which we don't expect in nature from Apple Servers). – Ayush Jul 04 '17 at 09:09
  • I would also suggest, you make sure - your app is not caching any device token. It might so happen that your app couldn't register new production device token & it returned cached one. (Just one guess). I believe you have made sure that all your devices (apps) are bundled using production certificate only. – Ayush Jul 04 '17 at 09:23
  • thanks and sorry for my delayed answer, I've kind of found the problem, but i don't post it as answer because Im not sure if I'm right. after days of having this issue on testFlight, I released the app on the App Store without any change, and its working now! no Invalid Token Error. I think maybe when the app is on the test flight, apple behaves it kind of random and sometimes registers the device in production env and s.t development(still not sure), so maybe testFlight should be just ignored hoping that everything will work fine on the App Store! – Arkhan Jul 08 '17 at 10:28
  • I have a similar issue in my app. When i switch between my Testflight version (which use Production) and sideloading the app (Sandbox), then i get the token for the wrong environment the first time the app is started. This is actually the old token. When i kill the app and restart it again, i retrieve the token for the correct token. I retrieve the token via the `func pushRegistry(registry: PKPushRegistry!, didUpdatePushCredentials credentials: PKPushCredentials!, forType type: String!)` callback. Unfortunately i didn't found a solution, but it is only a development issue. – J-Bossi Jul 28 '17 at 23:48
  • Hi @J-Bossi, wondering if you're still seeing this? We've just been trying to tracked down an issue and seem to get very similar symptoms—the first time the app is run after switch between testflight/dev it gets the wrong APNs device token – Sam Mason Aug 14 '17 at 11:45
  • I didn't find a proper workaround yet. I just told my developers and testers to restart the app once they switch between sideloading and testflight. – J-Bossi Aug 14 '17 at 12:51