Push notifications don't work in Apple Beta Testing (TestFlight) - ios

Push notifications worked fine with a Development provisioning profile, but once I tried putting the app on the Beta testing programme (TestFlight), they don't.
I tried following all the required steps when switching to a Production profile, but it still doesn't work. Here's what I have.
In the Member Center:
Certificate of type iOS Distribution.
App ID. Named (not wildcard). Push notifications enabled for both Development and Distribution - green lights - with all SSL certificates generated and uploaded.
iOS Distribution Provisioning Profile, that uses the above mentioned Certificate and App ID as well as lists Push Notifications among enabled services.
In XCode. Target > Build Settings > Code Signing:
Provisioning profile - iOS Distribution, same as in Member Center.
Code signing identity (both Debug and Release) - iPhone Distribution.
Am I missing something (not so) obvious? Any help would be greatly appreciated.

Everything seems correct. Maybe you should precise what is not working :
App not registering to APNS token at all
App correctly registering but push not received
Process to the following checks
App not registering to APNS token at all
Mobile Provision
Make sure you refresh your mobileprovisions through XCode after enabling push to be sure those includes the correct entitlements. You can check this by opening the mobile provision in an editor and look for the aps-environment key?
Registration to APNS
make sure the code to register to APNS does not depend on any personal settings (like a Push Id for some SaaS push service that is missing)
.
App correctly registering but push not received
Check that the pushToken received is sent to the correct environment of your server (the one that connect to APNS)
Check that your server is using the Production APNS Certificate

As it happens, I failed to provide full context in my question. I use Parse.com to handle my backend as well as push notifications. So what I was missing was a production certificate on Parse.com, not just a development one. So, if anyone else is using Parse and ran into a similar problem, I hope this is helpful.

Related

If push notification can be sent successfully on development device, why the app can't receive the push notification when installed ad-hoc?

I'm developing an app that uses push notification. When tested on development device (e.g. installed using cable connected to the Mac), it can receive push notification correctly. But when it's installed using ad-hoc means, no push notification received.
But, the app can obtain the device id on both development and ad hoc scenario. This is evident by the device id received and recorded on the server. The server receives device id on both development and ad hoc scenario. But even then, if the app is installed using ad hoc means, it's not receiving any push notification from the server.
PS:
I'm using Xcode 8.2.1 and Swift 3.
I have created the certificate using SSL push notification for distribution and development, and have included (double click) the certificate on the Xcode.
I have made sure that the capabilities for push notification is ON. Both steps on push notification are also has ticks.
I archived the app using Xcode automatically manage sign in. Xcode is supposed to linked in all the correct certificates for me, including the certificates for SSL push notification for distribution and development... right?
What is your thought on what's wrong with this, and the solution for this? Thanks.
EDIT:
When I tried to use manual code signing, here's what I got:
I can't resolve the status issue. I know that the debug is supposed to have different provisioning. But for now, that's not the main issue. If I can solve the status issue, I also can solve the different profile.
You need to make sure if the certificates for the push notification in adhoc environment are created fine. Secondly, the UDID is getting saved on server properly or not.
Firstly, you should check your uuid of mobile provision in ipa is correct by running command security cms -D -i yourprovisionname.mobileprovision in bash.
the trailing lines
<key>UUID</key>
<string>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</string>
you can unzip your .ipa file and find embedded.mobileprovision in your Payload/App
If mobileprovision is correct, you should check your certifications.
Note that The certification of production environment is different than sandbox.
After checking the certification, you can check the server side. When we push to a sandbox(development), we push to address gateway.sandbox.push.apple.com, and in the distributed environment, we push to gateway.push.apple.com(no sandbox).

Testflight - Universal Push Notification Client SSL Certificate - BadDeviceToken

I'm to trying to test my push notifications while utilizing TestFlight.
I can successfully receive a push notification on a device when I deploy directly to it from Xcode. However when I deploy the app to the device via TestFlight (as an external tester) I get "BadDeviceToken".
I have created a "Universal Push Notification Client SSL Certificate" and followed these apple instructions to the letter (I think). As per link:
"The client SSL certificate that is generated is a universal certificate that allows your app to connect to both the development and production environments."
Has anyone got any ideas?
Thanks
FYI:
Relevant Application Service:
iOS Certificates:
ok, this was my silly error. I am using Pushy.
You specify the environment like so:
apnsClient.connect(ApnsClient.PRODUCTION_APNS_HOST);
Unfortunately I had specified DEVELOPMENT_APNS_HOST before. It would seem that when you use TestFlight you have to specify the production apns host.
Thanks for everyone that looked over the question and answered.
You should try to re-create the certificates from scratch. Make sure that the certificates are production/distribution and not using APNS sandbox. Also, make sure it's on an actual approved device and not a simulator.
From the APNS Docs:
The specified device token was bad. Verify that the request contains
a valid token and that the token matches the environment
Also, check out these two links (first one is old):
iPhone APNS Device Tokens in sandbox vs. production
https://salesforce.stackexchange.com/questions/119615/send-push-notifications-to-ios-using-apns

Push notifications not received via TestFlight

My app is currently being tested by testers via TestFlight. The problem is that they don’t receive any push notifications sent. It’s working on my own device when connecting it to my mac and running the app directly from x-code.
I feel like I’ve tried almost everything, from changing certificate from dev to production to recreating a new production APNS certificate and build using a new profile referencing it, etc.
I know this question has been discussed on other topics but I never found the right answer in my case. I can't post images here because I don't have enough reputation but I have relevant screenshots.
Any help is welcome :)
Elements to help diagnostic :
It’s working on my device when I run the app directly from x-code.
The testers are asked properly if they want to authorize push notifications on their devices (at least the first install, after if they want to get asked again they have to do what’s described in Reset push notification settings for app)
The registering is working because I can see their devices tokens in the logs (but I have the feeling that the token is always the same, no matter if the app is built with the production or the dev certificate, not sure if it’s normal).
I have an APNS Production certificate.
I have a distribution profile, with “push notification” enabled. It’s linked with my “full” appID (and not the generic one with “*”).
I’m signin the build in release mode with the distribution certificate (not in debug mode), and I’m using the provisionning profile described above (the distribution one, linked with my app id)
And when I check in the "binary & entitlements" window just before submitting the build I see the the provisionning profile is correct and that "aps-environment" is set to "production".
Server-side : The APNS call is made by using javapns (https://code.google.com/p/javapns/) from a google app engine server. Like I said the notification are correctly received on my own device so I guess this call is working. We have a .p12 file generated from the APNS developpement certificate and a .p12 file from the APNS production certificate, and I've tried to make the call with both and it's not working. The server-side code hasn't change from the previous version and it was working in production with the app on the store. The problem is really focused on testing with testflight.
Thank you all !
If you followed Ray Wenderlich's tutorial and you made everything work in development mode, the issue most likely comes the fact that you now need to create a new .pem-file for production mode.
So, you need to perform exactly the same steps that you did with the development certificate (i.e. the .p12-file) you downloaded once more with the production certificate which you can obtain in the iOS dev center as well:

Push notifications not coming when we download the build from testflight or diawi iOS

I have successfully created the .pem and .p12 file by
http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
Tutorial.
We are using java as a server so I also exported my .p12 key using this link as there was an error of directly exporting the .p12 file
Cannot send push notifications using Javapns/Javaapns SSL handshake failure.
Everything is working great in debug mode. Whenever I install a build by xcode I receive the push notifications successfully everytime. But after archiving and uploading the build on testflight or diawi and then installing it on the device I didn't get any push notifications. I am successfully getting the device token from apns server. On debugging at server side we found that the device token they receive and send the notifications is invalid. This response is sent by the apns server to our java server. . I am using Xcode 6.0 or later and my app is compatible with ios7.0 or later. And yes I have made checks in registering for remote notifications for ios 8 and 7.Has anyone has faced this issue because earlier in xcode 5 series this hasn't happen. Please help
Any help will be appreciated. Thanks
If you followed Ray Wenderlich's tutorial and you made everything work in development mode, the issue most likely comes the fact that you now need to create a new .pem-file for production mode.
So, you need to perform exactly the same steps that you did with the development certificate (i.e. the .p12-file) you downloaded once more with the production certificate which you can obtain in the iOS dev center as well:
Here is the quote from the tutorial that you probably overread:
If you’re ready to release your app to the public, you will have to
repeat this process to make an Ad Hoc or App Store distribution
profile.
1.)Check if the pem file you have stored on your server is created by using a development certificate or distribution certificate, for push notifications to work through ttestflight you need to create a pem file in the distribution mode,
2.) also check if the gateway you are delivering to is gateway.push.apple.com:2195, and not the sandbox one,
3.)the notification tokens are also different for development and distribution profile, check all these scenarios and see
In order for push to work you have to use the exact same AppID for both creating APNs cert and Provisioning Profile. Wildcard profiles cannot be used for push notifications. May this be your problem(using wildcard or just different AppID for TestFlight/diawi)?

iOS: Production push notifications, Invalid token from APNS server

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 the notifications, and I have switch it to point to Apple's production servers.
However, I'm now getting an Invalid Token error back from the APNS servers.
I have the Archive scheme set to "Release", and I have Release set to use this distribution profile:
Inside that provisioning file, you can see that I have the environment set correctly:
Yet I still get the error. When I look in my database, I think the device token the app is returning to me is the same as the development one, so that could be the problem. But I don't know why it would be returning that, given that the app is signed correctly. This is a device I also used for testing, could that be a problem? Any other ideas about what's happening here?
Thanks!
EDIT: I'm not storing a token in my code, Eran's answer suggests that the only other possibilities are an old token in my database, or the app not being signed by a production profile. I'm cleared my database, so I know it's not the former, and as for the latter, I don't see how that could be the case, since I only have one distribution profile, and as I've shown above, it has the "aps-environment" key set correctly. XCode wouldn't even let me use a development profile for app store submission, would it? A few other possibilities:
Is it possible that something being wrong with key I'm sending with my notifications could cause "Invalid Token"? If so, can I regenerate this key for my existing profiles?
Isn't there another provisioning profile contained in the AppID for the purposes of push notifications? Could a problem with that cause the invalid token error?
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.
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.
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.
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"
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
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

Resources