2016-05-20 3 views
1

Im Moment verwende ich Schleife, um Bulk-Punkte zu senden, möchte ich Bulk Push in IOS senden, wie kann ich dies ohne Verwendung von Schleife senden.Wie kann ich Bulk Push in IOS senden ohne Schleife

ist hier mein 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; 
    } 

Kann mir jemand bitte sagen, wie ich dieses Problem beheben kann?

Antwort

2

Ich bin traurig, Ihnen zu sagen, aber Sie können nicht. Da die Apple API nur einen Token nach dem anderen benötigt, müssen Sie jede Benachrichtigung innerhalb einer Schleife senden.

See:
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/APNsProviderAPI.html

+0

dank @ David für Ihre Hilfe – Nikul

+0

https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html – pravindot17