Search code examples
iosiphonexcodeapple-push-notificationspem

iOS APNs push notification send successfully, but notification not receiving in mobile


Since Last week Friday (apr 23) everything is working, i received both sandbox and production notification. But when i check now, notification is not working. I checked my .pem file is valid till Dec 2021, When i run the below code the result is 'Message successfully delivered'. I don't know what happened. Please help me.

<?php
    $deviceToken = "a9eb9cd54446b5cad4fa3636dbe822b5d420126fdbb632ef79b4bf07bfd8b6b4";
    $passphrase = 'secret';

    $message = "Hello world!";

    $ctx = stream_context_create();

    $passphrase = 'secret';
    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'certi.pem');
    
    stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
  /* $fp = stream_socket_client(
                               'ssl://gateway.push.apple.com:2195', $err,
                               $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);*/
    $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err,$errstr, 60,STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
    
    if (!$fp){
        exit("Failed to tess connect: $err $errstr" . PHP_EOL);
    }
    $body = array('aps' => array('alert' => $message,'sound' => 'default','badge' => 1),'rewards_badge' => 1);
    
    $payload = json_encode($body);

    $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
    $result = fwrite($fp, $msg, strlen($msg));
    if (!$result){
        echo 'Message not delivered' . PHP_EOL;
    }else{
        echo 'Message successfully delivered' . PHP_EOL;
    }
    fclose($fp);
?>

Thanks


Solution

  • Me too man. I submitted a help request to Apple to ask them to help.

    I use the same test script. I notice that ssl://gateway.sandbox.push.apple.com:2195 is no longer valid. If your Apple devices aren't getting Apple push notifications

    This is the new domain name? api.sandbox.push.apple.com:443

    Sending Notification Requests to APNs

    • Legacy ports 2195 and 2196 are deprecated and will not be supported after March 2021.

    Me too man. Let's figure this out together like Apex Legends.

    I have submitted a TSI to Apple. They sent out an email on feb 10 saying:

    On March 29, 2021, token and certificate-based HTTP/2 connections to the Apple Push Notification service must incorporate the new root certificate (AAACertificateServices 5/12/2020) which replaces the old GeoTrust Global CA root certificate. To ensure a seamless transition and to avoid push notification delivery failures, verify that both the old and new root certificates for the HTTP/2 interface are included in the Trust Store of each of your notification servers before March 29.

    Note that Apple Push Notification service SSL provider certificates issued to you by Apple do not need be to updated at this time.

    Learn more about connecting to APNs.

    If you have any questions, contact us.

    Best regards, Apple Developer Relations

    Update - Mon May 3, after submitting a TSI to Apple Dev

    1. Push notifications stopped working for developers on March 31, 2021 after Apple migrated to a new APNS provider API (http/2 protocol).
    2. To continue using push, see this page: Sending Notification Requests to APNs
    3. On that page, these 3 items are of special interest to me:

    Registering Your App with APNs

    Establishing a Token-Based Connection to APNs

    Generating a Remote Notification

    What I learned?

    1. Revoke all developer account certificates related to APNS
    2. Make new certs and this time don't make any PEM files when installing them to your providing server. Also, make sure to stop using port 2195 when making a connection to APNS and use 443 or 2197.

    The great news? The new APNS provider API is still compatible with Objective C!

    🐆