Push notification not receiving on iphone

前端 未结 5 1380
梦谈多话
梦谈多话 2020-12-15 11:03

I am using this tutorial to learn push notification.



        
5条回答
  •  执念已碎
    2020-12-15 11:27

    First make sure that you're using:

    • The application is compiled with debug/release provision
    • your keychain has the devlopment/production push notification certificate

    then use the following code (been tested both dev & production)

    "; // Some Device Token
    
    
    // Notification content
    
    $payload = array();
    
    //Basic message
    $payload['aps'] = array(
    'alert' => 'testing 1,2,3..', 
    'badge' => 1, 
    'sound' => 'default',
    );
    $payload['server'] = array(
    'serverId' => $serverId,
     'name' => $serverName
    );
    // Add some custom data to notification
    $payload['data'] = array(
    'foo' => "bar"
    );
    $payload = json_encode($payload);
    
    $streamContext = stream_context_create();
    stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
    stream_context_set_option($streamContext, 'ssl', 'passphrase', "");
    
    
    $apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error,      $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
    
    
    $deviceToken = str_replace(" ","",substr($device_token,1,-1));
    echo $deviceToken;
    $apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '',      $deviceToken)) . chr(0) . chr(mb_strlen($payload)) . $payload;
    fwrite($apns, $apnsMessage);
    
    
    //socket_close($apns);
    fclose($apns);
    
    ?>
    

提交回复
热议问题