push notifications stopped working in app after cert update - ios

My cert for push notifications expired a few days ago. I updated it on the developer portal and put the new one for my server to use. Everything works not for the app that is downloaded from the app store.
When i try to load a in-dev build from x-code all push notifications fail. Apple responds back with message "Invalid Token".
I have literally done nothing. I just started it up and started testing to make sure everything is working. Is there some way to update the cert in the app or something of that sort??
NOTE: uploaded my app to testflight and everything works. Only does not work while developing right from xcode.

For developing you use different APN and Certificate that for
Production.
Apple generate different tokens for app in Debug and app
in Production.
Your server is using a Production certificate and a
Production APN.
TestFlight app is a Production ready app.
Now:
In Debug you send a Debug token to a server in Production, that Debug token is NOT registered on Apple Production APN.
In TestFlight you send a Production token to a server in Production, that Production token IS registered on Apple Production APN.
So all is working as intended.

Related

Is it possible to use same bundle ID for development and distribution in ios?

I am using onesignal plugin for push notifications in my android and ios app so I want to test push notifications first on development side and then I will upload it on ios app store. Or is there any best practice for implementation of onesignal push notification first for testing and then distribution.
Personal opinion, you do not need separate profiles/certificates for development and production anymore in case of APNs. Recently apple has made some changes. Now you only need one '.p8' push notification certificate from your 'developer.apple.com' account. You give this .p8 file to your backend team.
Xcode will automatically manage your production and development on your side.
This is what you have to do to make it work:
For the backend:
In your app delegate, inside the function where you get APNs token from apple. This APNs token will either be development or production. How does apple decide, which one to give? Well when you export an IPA/App locally, or upload it on test flight or on App store, Xcode will automatically give you production push notification APNs. When you install IPA/App locally using xcode to a phone connected to xcode or on simulator, Xcode will automatically give you development/staing push notification APNs token inside that function. And at that point you just have to send that token to your backend.
How will backend check if the user's token they are getting is production or development?
Using your URL, if it is staging, it will consider it as development APNs token.
If it is production URL, it will consider it as production APNs token.
What you have to make sure?
Make sure the Base URL is set to production if you are uploading app to test flight.
Make sure the Base URL is set to development if you are running app locally on simulator or your phone connected to your xcode.

How do I switch the certificate from development to production?

I am trying to testflight my app, but when I use notifications I get an error because I have a development APN instead of a production APN. My problem is uploading it to parse. First I created a development SSL Certificate, then I went back and did a Production SSL Certificate, but I am having trouble uploading the Production Certificate because It's not an APN, rather a Apple Push Services. I also created a Distribution Provisioning (ad hoc).
Apples Push Notification service is a bit strange:
On the client side:
If you build your client with Xcode you usually build a "Debug" version of your app. In that case the registerForRemoteNotification method will create a sandbox device token for you.
If you build a "Release" version of your app the same method create a production device token for you.
On the server side:
If you have a sandbox device token you can only send a push notification to that device if you use Apples sandbox Push Notification service with your sandbox SSL certificate.
If you have a production device token then you have to use Apples production push notification service with your production SSL certificate to send a push notification to that device.
The tricky part is:
if you only have a device token you will not know if it is a production device token or a sandbox device token.
if you want to use release and debug clients against the same server, that server has to use the sandbox and the production service at the same time. And you need a mechanism to decide when to use which service.
BTW: there is a nice tutorial by Ray Wenderlich which also contains a useful PHP script for easy testing.
http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1

will push notifications with Production-SSL certificate work when I'm still testing my app? How can I know it will work?

My push notifications are working fine with the sandbox model. I just verified that the production ssl certificate is working both with direct SSL-connection and with AWS SNS. However, my device is still producing the same push token as it produced for the sandbox, and this token is not working for production-level push notifications (rejected as invalid token by Apple server). Is it supposed to work? How can I make sure push notifications are working/will work for users who download the app from the app store?
Create a provisioning profile for "Ad Hoc" distribution, using your production certificate. Sign your app with that and install. Make sure your SSL connection to APNS knows which certificate to use, depending on whether client is production or dev.

iOS notifications don't work in production like in Test

I have a problem with push notifications in development\distribution (app that talk with production server).
We have the same certificate in test and in productions servers.
When I run my app on device that talk with the test DB (I save device token by email) I'm getting notification, but when the app talk with the production server, I never get notification...
the certificate file is same on both servers
I signing the app in the same way
What can be the problem?
Use the APNs Production iOS type certificate on your production server. If you use the certificate with the same name but with the type "APNs Development iOS" it will not send push notifications.

iOS: Push Notifications only work in Development, not Ad Hoc

I've had development Push Notifications working fine for a while now, and the app currently is undergoing testing with TestFlight. The test distribution works fine, but it doesn't seem like the notifications are being sent, I'm using the APNS gem with Rails to manage the connection and pushing the device token to the database after it's available in the App Delegate. I've verified that it's connecting to the correct gateway and that the code is set to use the correct pem file, but still nothing. If I rebuild it within XCode onto my device in development mode, and push from the development server it's fine.

Resources