APNS notification fails to be delivered (error code 8) - ios

When I try to execute an apple push notification on the server I get the following error:
com.notnoop.exceptions.ApnsDeliveryErrorException: Failed to deliver notification with error code 8
My server is a Java application. It is strange that the same server WAR file works OK locally (notifications are sent), but it does not work (with error above) when I deploy it to remote server (RedHat openshift.com).
Here is what I do:
In Xcode I archive my application and export it for Ad Hoc
distribution using Distribution Provisioning profile. The profile
contains "aps-environment production" entitlement.
In Apple
Developer center, I download the APNs production iOS certificate,
import it in my iMac Keychain and export a p12 file.
I deploy the
.p12 file to my server, where I use
https://github.com/notnoop/java-apns library to execute apple push
notifications. The library is initialized like this:
APNS.newService().withCert(certificateInputStream,"password").withProductionDestination().withDelegate(this).build();
When run, the client application successfully registeres for push
notifications and receives a token.
When the server tries to
execute a push notification, an exception is thrown:
com.notnoop.exceptions.ApnsDeliveryErrorException: Failed to deliver
notification with error code 8
Can you help? What could be the reason that the same setup works on a local but fail on a remote server?

It appeared to be another error. The server contained old deployment (war) file, which was still pointing to the sandbox APNS environment. After I redeployed manually, the problem is gone.

Related

Push notification is not received in Testflight

Im trying to implement Apple Push notification.
It is working fine in Local environment. But it is not working in test flight.
I have got Automatic signing enabled.
I have included the APNS entitlement file in my build with Key APS Environment and Value Development.
I have used both of the following urls in my server,
Sandbox: gateway.sandbox.push.apple.com, port 2195.
Production: gateway.push.apple.com, port 2195.
But still the push notification is not received from testflight mode. Why so?
Since your push notification is working fine on development but not on test flight.
You should check these as below:
Use the production SSL certificate to generate the .pem file on your push server when your app is using test flight.
Make sure your pem file and device token is right on your push server

Push token is not generating when app is installed using archive ipa file.Token is generating when app is installed with binary file

i have created in-house production push certificate not able to generate push token with iPA creation .Token is generating when app is installed with binary file through iTunes and app is installed through Xcode. Why it is happen like this can any one knows?
This is because we have 2 APNS environments - Production & Sandbox. When you generate a local build with Xcode, it gets auto signed with sandbox certs and you get connected to sandbox APNS. If your server side also using the sandbox push certificate, you will get a push with this device token.
To test production environment, you need right provisioning profile (profile with production key for .mobileprovision).
You can test APNS production environment building an AdHoc version of your App. The app will be using the production certificates and servers and it's purpose is exactly to test BEFORE you send it to AppleStore. Alternatively, you can test production pushes by downloading form App Store that is like more real time.

Send push message to apple sandbox

I'm currently working on push notification workflow developed by another developer of my company.
I have a question about the sandbox for push notification.
I have generated a .pem for my production environment.
I have tested id with openssl as describe in this tutorial.
When i make the test to gateway.sandbox.push.apple.com url, the connection is ok even though i don't use the developement key and cert files (i use the prod file).
If i build and send push message to gateway.sandbox.push.apple.com with my prod pem file, the message will be send to the prod devices or dev devices ?
There's no such thing as a production device or a development device. There are devices with either a production build or a development build of your application.
You can only send a push to a development build of your app using the development environment, and likewise you can only send a push to a production build of your app using the production environment.
Production and dev builds are signed using different profiles, and this results in the push token that your app obtains being different, if you try to send a push using the sandbox environment but using a production push token then it will be rejected, and similarly attempting to use the production environment with a dev push token.
You need to set your gateway proper, use the proper PEM whether Dev PEM or Dist PEM. Xcode needs Dev profile and certificate to run and test with Dev PEM

Push notification delivers from local env, but not from server

I'm trying to get my server to deliver push notifications via Apple's Push Notification service. (APNs)
My setup is as follows:
Cordova HTML/JS app
API in Rails on VPS via https
Houston gem for Push Notifications
I've created a certificate for development on my mac. When I run my server locally it successfully sends the notification to my iPhone.
I'm now trying to get it working on my server but without luck. I've generated a CSR locally, uploaded it in Apple's iOS App ID's editor and downloaded the CER. I then exported the CER to p12 with Keychain Access and converted that to a PEM file with the following command:
openssl pkcs12 -in apn_production.p12 -out apn_production.pem -nodes -clcerts
Houston needs this PEM file to send push notifications, I've done the same for development and it worked, but it needs to send from a server now, which could be the problem, I don't get any errors though. The notifications just don't arrive, which could be a production/development mistake I'm making.
I also tried creating a CSR file on my server and upload that via the iOS App ID's editor, but when I download the CER and open it in Keychain Access I'm not able to export it to P12, only to CER, PEM and P7B. Also there isn't a private key in this file, which there is within my locally created development certificate. Also when I export it to PEM and use it with Houston on my server it throws an error that the certificate is invalid.
Another thing I tried was upload the CSR generated by my VPS on the Apple Push Certificates Portal. This throws an error mentioning the certificate is invalid.
There's a couple things I'm not sure of:
1. Am I in development or production mode?
The app is not yet in the app-store, but it is in beta mode to download via TestFlight and push notification need to be send from my server. Is this a production environment or development or do I need to define this manually somewhere before building the App?
2. Is it possible to use a locally generated CSR for a PEM to be used on my server?
Am I right that I need a server generated CSR to start with when I finally need a PEM to send push notifications with from my server?
3. What do do now, how should I debug?
The PEM generated from my locally generated CSR is now uploaded to my server and Houston doesn't throw errors whatsoever. The push notifications don't arrive though, so, what should I do, can I trace these push notifications somewhere? Is there some APN logfile which I can read?
1) You need to use production certificates for sending push notifications via test flight.
2) You do not need a server generated CSR. You only need a valid ".pem" for sending push notification.
3) You need to remove sanbox (sandbox mode) from push notification url in push sending script. Also check if port 2195 of your server is open for communication or not because APNS communicates via this port.

Push notifications not working in production mode

I am implementing push notifications, it's working in development mode.
In production mode, when I run the application I get this message in Xcode but the application installs on the device.
launch failed: failed to get the task for process 11288
After opening the app on device I get token id, but not get the notification, when I run simple.php file in terminal I get message as
connected to APN
Message successfully delivered
I have used AdHoc production provisioning certificate to test the application.
Can you tell me how to test push notifications in production.
You need to use a production push certificate, which you can generate the same way you do with a development certificate (just choose production), as well as change your server address from gateway.sandbox.push.apple.com to gateway.push.apple.com...
EDIT: You are not allowed to debug production apps, which is why you get that Xcode error in production mode...
First, You get the following error
launch failed: failed to get the task for process 11288
Because, you are running app in Production (adhoc/distribution/release) scheme mode.
Second,Your pem file and its password should be correct. Also make sure you are using the correct gateway for Production.
We could help you more, if you can share your server file here.
Thanks

Resources