2

I have integrated the FCM push notification functionality in the PHP. Now, notification is working fine but the badge number is not working.

I have added the badge = 1but every time is't showing 1 instead of increment badges number. I want to send the auto incremented badge number.

Please see my php file code:

 <?php

    $ch = curl_init("https://fcm.googleapis.com/fcm/send");

    //The device token.
    $token = "DEVICE_TOKEN_HERE"; //token here 

    //Title of the Notification.
    $title = "Title Notification";

    //Body of the Notification.
    $body = "This is the body show Notification";

    //Creating the notification array.
    $notification = array('title' =>$title, 'text' => $body, 'sound' => 'default', 'badge' => '1');

    //This array contains, the token and the notification. The 'to' attribute stores the token.
    $arrayToSend = array('to' => $token, 'notification' => $notification,'priority'=>'high');

    //Generating JSON encoded string form the above array.
    $json = json_encode($arrayToSend);
    //Setup headers:
    $headers = array();
    $headers[] = 'Content-Type: application/json';
    $headers[] = 'Authorization: key=API_KEY_HERE'; // key here

    //Setup curl, add headers and post parameters.
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
    curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);       

    //Send the request
    $response = curl_exec($ch);

    //Close request
    curl_close($ch);
    return $response;

?>

Please help me!!! Thanks.

AL.
  • 36,815
  • 10
  • 142
  • 281
mageDev0688
  • 566
  • 4
  • 27

1 Answers1

0

This is the expected behavior. iOS doesn't auto-increment the badge you send. You'll have to determine the supposed to be value of the badge on your server-side before you send it.

Also see this post.

Community
  • 1
  • 1
AL.
  • 36,815
  • 10
  • 142
  • 281