2014-11-03 44 views
0

我有這個功能在PHP中,將發送2通知給應用程序A和應用程序B時,有一個行動的功能。 但是,我只會在一個APP中收到1個通知。 我正在使用apnsphp來執行通知推送。無法接收設備中的所有ios通知使用php apns push

以下是我的情況: 我有一個2應用程序:應用程序A和應用程序B 這兩個應用程序都使用不同的apns證書。

是否存在apns證書緩存的可能性?

情景1) 當記錄到IPAD與APP甲&同時登錄到IPAD與APP B,推送通知接收到用於APP A和不用於APP B.

方案2) 當使用APP A登錄到IPAD並使用APP B登錄到iPhone(單獨設備)時,接收APP A的推送通知,而不是APP B接收推送通知。

場景3) 當從APP A ,並通過APP B登錄到iPad(相同設備)或iPhone(單獨設備),推送通知收到應用程序B。

即時得到這個錯誤來自apnsphp:

["ERRORS"]=> array(2) { 
[0]=> 
array(3) { 
["identifier"]=> int(1) 
["statusCode"]=> int(999) 
["statusMessage"]=> string(53) "Internal error (0 bytes written instead of 223 bytes)" 
} 
[1]=> 
array(5) { 
["command"]=> int(8) 
["statusCode"]=> int(8) 
["identifier"]=> int(1) 
["time"]=> int(1415012295) 
["statusMessage"]=> string(13) "Invalid token" 
} 
} 

下面是日誌:

Tue, 04 Nov 2014 10:02:25 +0800 ApnsPHP[4136]: INFO: Trying tls://gateway.push.apple.com:2195... 
Tue, 04 Nov 2014 10:02:26 +0800 ApnsPHP[4136]: INFO: Connected to 
tls://gateway.push.apple.com:2195. Tue, 04 Nov 2014 10:02:26 +0800 ApnsPHP[4136]: INFO: Sending 
messages queue, run #1: 1 message(s) left in queue. Tue, 04 Nov 2014 10:02:26 +0800 
ApnsPHP[4136]: STATUS: Sending message ID 1 [custom identifier: CakeApns] (1/3): 166 bytes. Tue, 
04 Nov 2014 10:02:27 +0800 ApnsPHP[4136]: INFO: Disconnected. 

Tue, 04 Nov 2014 10:02:27 +0800 ApnsPHP[4136]: INFO: Sending messages queue, run #1: 1 message(s) 
left in queue. Tue, 04 Nov 2014 
10:02:27 +0800 ApnsPHP[4136]: STATUS: Sending message ID 1 [custom identifier: CakeApns] (1/3): 
221 bytes. Tue, 04 Nov 2014 10:02:27 +0800 ApnsPHP[4136]: ERROR: Unable to send message ID 1: 
Internal error (0 bytes written instead of 221 bytes) (999). Tue, 04 Nov 2014 10:02:27 +0800 
ApnsPHP[4136]: INFO: Trying tls://gateway.push.apple.com:2195... Tue, 04 Nov 2014 10:02:28 +0800 
ApnsPHP[4136]: INFO: Connected to tls://gateway.push.apple.com:2195. Tue, 04 Nov 2014 10:02:28 
+0800 ApnsPHP[4136]: INFO: Sending messages queue, run #2: 1 message(s) left in queue. Tue, 04 
Nov 2014 10:02:28 +0800 ApnsPHP[4136]: STATUS: Sending message ID 1 [custom identifier: CakeApns] 
(2/3): 221 bytes. Tue, 04 Nov 2014 10:02:28 +0800 ApnsPHP[4136]: ERROR: Unable to send message ID 
1: Invalid token (8). Tue, 04 Nov 2014 10:02:28 +0800 ApnsPHP[4136]: INFO: Disconnected. Tue, 04 
Nov 2014 10:02:28 +0800 ApnsPHP[4136]: INFO: Trying tls://gateway.push.apple.com:2195... Tue, 04 
Nov 2014 10:02:29 +0800 ApnsPHP[4136]: INFO: Connected to tls://gateway.push.apple.com:2195. Tue, 
04 Nov 2014 10:02:29 +0800 ApnsPHP[4136]: INFO: Sending messages queue, run #3: 1 message(s) left 
in queue. Tue, 04 Nov 2014 10:02:29 +0800 ApnsPHP[4136]: WARNING: Message ID 1 [custom 
identifier: CakeApns] has an unrecoverable error (8), removing from queue without retrying... 
Tue, 04 Nov 2014 10:02:30 +0800 ApnsPHP[4136]: INFO: Disconnected. 

回答

0

我通過編輯ApnsComponent文件來解決它。

我已經添加了一個新的公共變量:previousData 此變量將存儲它所連接的當前combined_cert_path。當我切換我的證書路徑時,我將檢查證書路徑是否與我連接的證書路徑相同。如果不一樣,我會重新連接到apns。如果它是相同的路徑,我會返回true。

檢查是爲了防止服務器重新連接並增加發送時間。

private function __connect() { 
    if($this->previousData == ""){ 
      $this->previousData = $this->combined_cert_path; 
      $this->__push = new ApnsPHP_Push($this->env, $this->combined_cert_path); 
      $this->__push->setProviderCertificatePassphrase($this->cert_passphrase); 

      $logger = new ApnsPHP_Log_Custom(!$this->__logEnabled); 
      $this->__push->setLogger($logger); 
      //$this->__push->setSendRetryTimes($this->__sendRetryTimes); 
      $this->__push->connect(); 
      return $this->__logError(); 
    } 
    else if($this->previousData != $this->combined_cert_path){ 

      $this->previousData = $this->combined_cert_path; 
      $this->__push = new ApnsPHP_Push($this->env, $this->combined_cert_path); 
      $this->__push->setProviderCertificatePassphrase($this->cert_passphrase); 

      $logger = new ApnsPHP_Log_Custom(!$this->__logEnabled); 
      $this->__push->setLogger($logger); 
      //$this->__push->setSendRetryTimes($this->__sendRetryTimes); 
      $this->__push->connect(); 
      return $this->__logError(); 
    }else{ 
     return true; 
    } 
}