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 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题