无法使用php apns push在设备中接收所有ios通知

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

1个回答

I resolved it by editing the ApnsComponent file.

i've added in a new public variable : previousData This variable will be storing the current combined_cert_path it is connected. When i switch my cert path, i will check if the cert path is the same as my connected cert path. If it is not the same, i will reconnect to apns. If it is the same same path, i will return true.

The checking is to prevent server to reconnect and increase the sending time.

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;
    }
} 
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐