0

I have this function in php that will send 2 notifications to App A and App B when there is an action to the function. However, I will only receive 1 notifications in one APP. I am using apnsphp to do the pushing of notifications.

Below are my situation: I have a 2 app: app A and app B Both app are using different apns cert.

is there a possibility of apns cert cache?

Scenario 1) When logged in to IPAD with APP A & logged in to IPAD with APP B at the same time, Push notification is received for APP A and not for APP B.

Scenario 2) when logged in to IPAD with APP A and logged in to iPhone (separate device) with APP B, Push notification is received for APP A and not for APP B.

Scenario 3) when logged OUT from iPad with APP A, and logged in to iPad (same device) or iPhone (separate device) with APP B, Push notification is received App B.

Im getting this error from 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" 
 } 
 } 

Below are the logs:

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. 
4

1 回答 1

0

我通过编辑 ApnsComponent 文件解决了这个问题。

我添加了一个新的公共变量:previousData 这个变量将存储它连接的当前组合证书路径。当我切换我的证书路径时,我将检查证书路径是否与我连接的证书路径相同。如果不一样,我将重新连接到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;
    }
} 
于 2014-11-04T03:50:51.460 回答