Frustration Level: 🤬🤬🤬🤯
SOLVED: ✅ 
PHP Script Download Included in Solution:
 💾 

I spent many hours writing and debugging an Apple Push Notification service (APN) test using a JSON web token (JWT).

Apple's Developer documentation: 
https://developer.apple.com/documentation/usernotifications/sending-push-notifications-using-command-line-tools

The original test from the Mac command line worked perfectly using Apple's documentation. But when the script was moved to a cPanel environment and PHP 8.3, it suddenly stopped working.

Follow Apple's instructions to register your app, get the APN certificate (Developer website) and Private Key (from the Developer website in Certificates, Identifiers & Profiles/Keys ), and turn on the APN service in your app in Xcode.

  • Converting the AuthKey.p8 to a .pem format IS NOT REQUIRED. The AuthKey in its .p8 format works just fine. Apple's documentation is not correct. 
  • The "App ID" is the bundle identifier of the app you registered on Apple Connect: GridQ.com.TestApp
  • You must write code in your app to get the device token. The APN will use the device token to notify that device. Yes, if you want to send an APN to another device, you will need the device token for THAT device, too.
  • Ensure your web server firewall is not blocking Port 2195
  • Ensure the server antivirus or server host firewall isn't blocking SSL scripts or ports.

Here is the PHP test script that worked to send an APN message to Apple's sandbox, which I then received on my iPhone.

It is in ZIP format. Don't forget to edit all of the placeholder variables to your details.

By the way, this also works in the MAMP environment running on a Mac or PC.
I highly recommend MAMP to develop projects securely: https://www.mamp.info/

Enjoy!

PS - Be sure to check back. I am working on getting the PHP script to read the device tokens using a Google Firestore database. Stay tuned!

PHP Script: Apple Push Notification service (APNs) test using a JSON web token (JWT)

Download the PHP Script


Direct link to the article:  
https://www.gridq.com/dev-notes/testing-apple-push-notification-service-apn-using-a-json-web-token-jwt-on-a-cpanel-server-with-php


tags: iOS, APNs, Apple Push Notification, PHP 8.3, cPanel