mhtt
V2EX  ›  问与答

请教下 ios 消息推送的问题

  •  
  •   mhtt · Dec 12, 2016 · 1264 views
    This topic created in 3448 days ago, the information mentioned may be changed or developed.
    <?php
    $message = "hello";
    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'apns.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);
    if (!$fp)
    {
        
    }
    $body['aps'] = array(
        'alert' => $message,
        'sound' => 'default'
        );
    $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)
    {
    
    }
    else
    {
        
    }
    fclose($fp);
     ?>
    <html>
        <body>这是一个页面</body>
    </html>
    

    php 实现了 APNs 的推送,但问题在于,我想达到的效果是当访问这个页面的时候,立刻显示页面的内容(这是一个页面),但现在实际情况是当访问这个页面的时候,会是空白页面,只有当推送完成后,才显示页面的内容。

    大家还有什么好的方式呢?

    3 replies    2016-12-19 00:32:25 +08:00
    pupboss
        1
    pupboss  
       Dec 12, 2016
    这跟 APNS 有什么关系....
    推送完你 echo 一下` <body>这是一个页面</body>` 不就行了
    pupboss
        2
    pupboss  
       Dec 12, 2016
    看错了不好意思,试试把 php 代码写下面,实在不行等页面 load 完再触发 APNS
    mkeith
        3
    mkeith  
       Dec 19, 2016
    加载完了 js 调用接口啊
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5501 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 06:44 · PVG 14:44 · LAX 23:44 · JFK 02:44
    ♥ Do have faith in what you're doing.