douliang6563 2016-05-20 11:57
浏览 43
已采纳

如何在不使用循环的情况下发送ios批量推送

Right now I use loop to send bulk points, I want to send bulk push in ios, how can I send this without using loop.

Here is my code:

function sendToBulkIphone($artistID,$type="artist") {
            $deviceToken            =       $this->deviceToken;
            $message                =       $this->message;
            $postid                 =       $this->postid;
            $notificationtype       =       $this->NotificationType;
            $time                   =       $this->time;
            $ctx = stream_context_create();
            stream_context_set_option($ctx, 'ssl', 'local_cert', 'pushkey/artist_'.$artistID.'/ck_user_production.pem');
            stream_context_set_option($ctx, 'ssl', 'passphrase', '1234'); STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
            STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
            $fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

            if (!$fp)
            exit("Failed to connect: $err $errstr" . PHP_EOL);
            $body['aps'] = array(
                                                    'alert' => $message,
                                                    'sound' => 'default'
                                            );
            $body['title']="Notification";
            $body['message']=$message;
            $body['postid']=$postid;
            $body['NotificationType']=$notificationtype;
            $body['time']=$time;

            for($n=0;$n<count($deviceToken); $n++) {
                // Build the binary notification
                $payload = json_encode($body);
                $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken[$n]). pack('n', strlen($payload)) . $payload;

                $result = fwrite($fp, $msg, strlen($msg));//, strlen($msg)

                if (!$result) {
                        $jsondata['message'] = 'Message not delivered';
                        $jsondata['status'] = 0;
                }
                else {
                        $jsondata['message'] = 'Message successfully delivered';
                        $jsondata['status'] = 1;
                }
            }
            fclose($fp);
            return true;
    }

Can anyone please tell me how can I resolve this issue ?

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料