在Payload中隐藏推送通知中的URL

时间:2013-11-19 05:22:28

标签: php apple-push-notifications apns-php

我将来自PHP的URL和一条消息作为推送通知发送到ios设备。我想要的是我想发送带有一个URL和消息的推送通知,但必须隐藏URL。当用户在ios设备上看到PNS时,他/她只能看到消息而不能看到该URL。就像whatsapp messenger

这是我的PHP代码

// Open a connection to the APNS server
 $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 connect: $err $errstr" . PHP_EOL);
 echo 'Connected to APNS' . PHP_EOL;
 // Create the payload body
 $body['aps'] = array(
       'badge' => +1,
       'alert' =>$message,
       'sound' => 'default'
      );
 // Encode the payload as JSON
 $payload = json_encode($body);
 // Build the binary notification
 $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
 // Send it to the server
 $result = fwrite($fp, $msg, strlen($msg));

1 个答案:

答案 0 :(得分:2)

您应该将网址放在aps字典之外:

{

    "aps" : {

        "alert" : "<Your message>",

        "badge" : <your badge>,

        "sound" : "default"

    },

    "url" : "http://www.some.url.com"

}

我不知道php,所以我无法提供确切的代码。