简体   繁体   English

使用FCM推送通知IOS

[英]push notifications IOS using FCM

I am using FCM to send push notification to IOS app, IOS dev provide me device token and SERVER_KEY, I search on google and tried different solutions but nothing worked for me , So let me know what is wrong with my code, Getting error { "multicast_id": 8569689262516537799, "success": 0, "failure": 1, "canonical_ids": 0, "results": [ { "error": "InvalidRegistration" } ] } Thanks in advance 我正在使用FCM向IOS应用发送推送通知,IOS开发人员向我提供了设备令牌和SERVER_KEY,我在google上搜索并尝试了不同的解决方案,但对我没有用,所以让我知道我的代码有什么问题,获取错误{“ multicast_id“:8569689262516537799,” success“:0,” failure“:1,” canonical_ids“:0,” results“:[{”错误“:” InvalidRegistration“}]} 预先感谢

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

    //The device token.
    $token = "c2420d68a0838d8fb6b26ef06278e899de73a149e93c9fe13df11f70f3dd5cc1"; //token here
    //Title of the Notification.
    $title = "Carbon";

    //Body of the Notification.
    $body = "Bear island knows no king but the king in the north, whose name is stark.";

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

    //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);
    //print_r($json); die();
    //Setup headers:
    $headers = array();
    $headers[] = 'Content-Type: application/json';
    $headers[] = 'Authorization: key=AAAAx6P1Nz0:APA91bEqkVCA9YRw9gpUvmF8UOVrYJ5T8672wfS_I7UAT3dA0g1QS7z-Z4fpn8JMiJ5kFRz9ZGc2K64hKZG-4__PAUqm733hqNDuFCDv9'; // 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);
    //curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);


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

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

    //return $response;

token number ur sending is most probably wrong. 您发送的令牌号很可能是错误的。 try "/topics/all" this will send notification to all the users registered. 尝试“ / topics / all”,这将向所有注册用户发送通知。

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

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