iOS push notification issue It's working some time and not working sometime

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I have checked my code by running from URL it's working fine while I am trying from the browser. but it's not working with the curl code and I can not find the solution. curl_error gives nothing. I have read that "devices won't always connect to the same public IP address for notifications. " but what is the solution for that Please suggest what is wrong with the curl code/ other issues possibilities.

Here is the curl code

$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, BASE_URL .'api-v2/admin_notification_cron.php');
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
$result = curl_exec($ch );
curl_close( $ch );

And admin_notification_cron.php file fetch data from the database and call the sendNotification function after fetching 20 data from database every 1 Minuit

Below is the sendNotification function code:

    function sendToIphone($deviceToken, $data)
    {

    $data['push_image'] = (($data['push_image']!='')?PHOTO_URL.'push/'.$data['push_image']:'');   

    $passphrase = '';
    $ctx = stream_context_create();

    stream_context_set_option($ctx, 'ssl', 'local_cert', 'apns-dev-cert.pem');
    stream_context_set_option($ctx, 'ssl', 'passphrase', '');
    $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

    $type = ($data['type']!='')?$data['type']:'0';

    if ($data['message']=='add_job' || $data['message']=='process') {
        //$sound = 'newrequest.mp3';
        $sound = 'default';
    } else {
        $sound = 'default';
    }


    $body['aps'] = array(
        'alert' => stripslashes($final_message),
        'title' => APP_TITLE,
        'job_id' => $data['job_id'],
        'user_id' => $data['user_id'],
        'created'=> $data['created'],
        'type'=> $type,
        'sound' => $sound,
        "mutable-content"=> 1,
        "category"=> "rich-apns",
        "image-url"=> $data['push_image'],
        'badge' =>
                                                
                                                
0 views
0 shares
profilepic.png
manpreet 2 years ago

There are some thumb rules to implement APNS.

  • Curl connection should be closed after delivered notification.

  • You have to wait until your previous notification was not delivered.

If you are executing all code in loop then some notification delivered and rest of notification will be discarded.

To fix your issue you have put some delay between two notification triggered or fire notificationafter previous notification delivered.

OR

You can use Third party Notification tools

FCM

OneSignal

It will manage automatically.


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.