简体   繁体   English

iOS PushNotification iPhone和iPad

[英]iOS PushNotification iPhone and iPad

I have made one universal app having push notification feature. 我制作了一个具有推送通知功能的通用应用程序。 I am sure you will also get surprised by reading this. 我相信您也会通过阅读这篇文章而感到惊讶。

In Production version (App store build) I am receiving Push message on my iPad while i haven't receive such Notification on my iPhone. 在正式版(应用商店构建)中,我在iPad上收到推送消息,而在iPhone上没有收到此类通知。

App is build for universal so of course code is same more over Appdelegate is same for both iPad and iPhone. App是为通用构建的,因此代码当然比iPad和iPhone的Appdelegate相同。

I have been making iOS since last 4 year never faced such issue. 自从过去四年以来,我一直在制作iOS,从未遇到过此类问题。

One thing is for sure that my push notification implementation is correct otherwise i will never get push message on my iPad. 一件事可以肯定,我的推送通知实现是正确的,否则我将永远不会在iPad上收到推送消息。

Any help ???? 有帮助吗????

Thanks, Parth 谢谢,Parth

Amendment: 修订:

Please check below PHP code, Same code (copy/Past) working for my another app and for this it wont. 请检查以下PHP代码,相同的代码(复制/粘贴)可用于我的另一个应用程序,因此不会。 Again If i send push on single device i am receiving on all, but if i try to send to all device by using loop i have just receive on one device. 再说一次,如果我在单个设备上发送推送消息,那么我将在所有设备上接收消息,但是如果我尝试使用循环发送到所有设备,则我只是在一个设备上接收消息。 (probably first row of table ) (可能是表格的第一行)

$payload = json_encode($body);
for($i = 0; $i<count($deviceTokens); $i++) {
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '',$deviceTokens[$i])) . pack("n",strlen($payload)) . $payload;
fwrite($fp, $msg);
}
fclose($fp);

Here i place echo in for loop and i got all register devices. 在这里,我将echo放入for循环中,并且得到了所有寄存器设备。

for($i = 0; $i<count($deviceTokens); $i++) {

pushnotification_ios($deviceTokens, "Your Message");
}

Call this function in loop.. 循环调用此函数。

function pushnotification_ios($device_token, $message){

        $passphrase = "Your_PEM_File_Password_Here";

        $ctx = stream_context_create();
        stream_context_set_option($ctx, 'ssl', 'local_cert', YOUR_PEM_FILE_PATH_HERE);
        stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
    // use this when you in sandbox mode..
        $fp = stream_socket_client(
            'ssl://gateway.sandbox.push.apple.com:2195', $err,
        $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
    // use this when you in development mode..
    //  $fp = stream_socket_client(
    //  'ssl://gateway.push.apple.com:2195', $err,
    //$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

        $body['aps'] = array(
            'badge' => $badge,
            'alert' => $message,
            'sound' => 'default',
            'content-available' => '1'
        );
    //echo "<pre>"; print_r($body);
        $payload = json_encode($body);

        $msg = chr(0) . pack('n', 32) . pack('H*', $device_token) . pack('n', strlen($payload)) . $payload;

        $result = fwrite($fp, $msg, strlen($msg));  //echo "<pre>"; print_R($result);
        /*
        if (!$result){
            $data = array(
                'Message' => 'Message not delivered' . PHP_EOL
                );
            }  else {
        $data = array(
                'Message' => 'Message successfully delivered' . PHP_EOL
                );
        } //echo "<pre>"; print_R($result); */

        fclose($fp);
    return $result;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM