du7535 2014-11-03 09:26
浏览 57

无法使用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. 
  • 写回答

1条回答

  • doukang8949 2014-11-04 03:50
    关注

    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;
        }
    } 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问