首页 > 解决方案 > "Delivered Message to APNS" but not showing notification in Production with ios13 (PHP)

问题描述

i have a problem with Notifications in ios13. If i use gateway.sandbox i can see the notification, but i'have downloaded the app directly from AppStore. Instead using gateway.apple i see 'Delivered Message to APNS', but nothing on my device. I also tried to recreate the Certificate, .p12 and .pem file.

Any idea? Thank you

This is my php

public function iOS($data, $devicetoken) 
{
    // $tHost = 'gateway.sandbox.push.apple.com';

    $tHost = 'gateway.push.apple.com';
    $tPort = 2195;

    $tCert = 'pushcert.pem';
    $tPassphrase = 'pushcertpsw12';
    $tToken = $devicetoken;

    $tSound = 'default';

    $tPayload = 'APNS payload';

    $tBody['aps'] = array(

    'apns-priority' => 10,

    'badge' => +1,

    'alert' => $data['mtitle'] .' ' .$data['mdesc'],

    'sound' => 'default'

    );

    $tBody ['payload'] = $tPayload;

    $tBody = json_encode ($tBody);

    $tContext = stream_context_create ();

    stream_context_set_option ($tContext, 'ssl', 'local_cert', $tCert);

    stream_context_set_option ($tContext, 'ssl', 'passphrase', $tPassphrase);

    $tSocket = stream_socket_client ('ssl://'.$tHost.':'.$tPort, $error, $errstr, 30, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $tContext);

    if (!$tSocket)

        exit ('APNS Connection Failed:' .$error. ' ' .$errstr . PHP_EOL);

    $tMsg = chr (0) . chr (0) . chr (32) . pack ('H*', $tToken) . pack ('n', strlen ($tBody)) . $tBody;

    // Send the Notification to the Server.

    $tResult = fwrite ($tSocket, $tMsg, strlen ($tMsg));

    if ($tResult)

        echo 'Delivered Message to APNS' . PHP_EOL;

    else

        echo 'Could not Deliver Message to APNS' . PHP_EOL;

    // Close the Connection to the Server.

    fclose ($tSocket);

标签: phpiosswiftiphone

解决方案


APNS令牌有两种不同的环境;沙盒和生产。它们需要完全独立的设置、权限、注册和推送设置。将沙盒 APNS 通知推送到生产令牌将不起作用,与将生产 APNS 推送到沙盒令牌相同。

如果您已在 Sandbox 中验证但未在生产中验证,则可能需要复制所有权限和证书以进行生产。还要仔细检查您使用 PHP 代码推送到的位置,并确保它是正确的环境(沙盒与产品)。


推荐阅读