Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facing problems in ios push notification php code

Tags:

php

ios

I use this code in php...

function pushnotificationios( $deviceToken, $message, $badges){
        $passphrase = "12345";
        $ctx = stream_context_create();
        stream_context_set_option($ctx, 'ssl', 'local_cert', $_SERVER['DOCUMENT_ROOT'].'/include/ck.pem');
        stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
        $fp = stream_socket_client(
            "ssl://gateway.push.apple.com:2195", $err,
        $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); 
        $body['aps'] = array(
            //'badge' => $badges,
            'badge' => "+1",
            'alert' => $message['message'],
            'sound' => 'default',
            'content-available' => '1'
        );
        $body['msg'] =$message;
        $payload = json_encode($body);
        $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
        $result = fwrite($fp, $msg, strlen($msg));
 //echo "<pre>"; print_r($result);
        fclose($fp);
        return $result;
    }

.pem file and their password is correct. but when i hit this function then only on production mode it give me return false;

$result = pushnotificationios( $deviceToken, $message, $badges);
 echo "<pre>"; print_r($result);

And it takes too much time to response.

Currently i am not find any solution.. my api is going to apple and my notifications is not working. The interesting thing is its a chating app and whole app is based on notifications. Its a bad day for me.

Please help if something happen good for me for app.

like image 758
SuReSh Avatar asked May 27 '15 07:05

SuReSh


People also ask

Why push notification is not working for iOS?

You can fix an iPhone that's not getting notifications by restarting it or making sure notifications are turned on. You should also make sure your iPhone is connected to the internet so apps can receive notifications. If all else fails, you should try resetting the iPhone — just make sure to back it up first.

Why push notifications are not reliable?

Android push notifications sent via GCM / FCM are not reliable due to various issues with GCM's underlying architecture [1] [2] [3]. Push notifications may be delayed, rate-limited, lost in transit, or arrive in a different order than which they were sent.

Do push notifications work on iOS?

An iOS push notification is a message that pops up on an Apple device such as an iPhone. Before receiving push notifications from an app, iOS device users must explicitly give permission. Once a user opts-in, mobile app publishers can send push notifications to the users' mobile devices.

How do I test iOS push notifications?

To send a test push, go to Mobile Apps > Integrations > Test Push. Use the Apple Sandbox Certificates for Xcode and the Apple Production Certificates when testing from TestFlight.


1 Answers

In production mode don't use sandbox url

 $fp = stream_socket_client(
        "ssl://gateway.push.apple.com:2195", $err,
    $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); 
like image 137
abh Avatar answered Oct 31 '22 01:10

abh