2014-11-03 92 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; 
    } 
}