Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php向ios设备发送带有fcm令牌的远程通知_Php_React Native_React Native Firebase - Fatal编程技术网

使用php向ios设备发送带有fcm令牌的远程通知

使用php向ios设备发送带有fcm令牌的远程通知,php,react-native,react-native-firebase,Php,React Native,React Native Firebase,我是制作ios应用程序的本地开发者 我正在努力实现使用fcm获取远程通知 我们的后端开发人员使用php,他也是android开发人员 因此,他为fcm开发api的方式针对android进行了优化 这是密码 function sendFCM($notif_array, $id) { $API_KEY = "API key"; $url = 'https://fcm.googleapis.com/fcm/send'; $keys = array_keys($notif_ar

我是制作ios应用程序的本地开发者

我正在努力实现使用fcm获取远程通知

我们的后端开发人员使用php,他也是android开发人员

因此,他为fcm开发api的方式针对android进行了优化

这是密码

function sendFCM($notif_array, $id) {
    $API_KEY = "API key";
    $url = 'https://fcm.googleapis.com/fcm/send';

    $keys = array_keys($notif_array);
    $fields = array (
            'registration_ids' => array (
                    $id
            ),
            // 'data' => array (
            //         "message" => $message,
            //         "type" => $notif_type
            // )
            'content_available'=>true,
            'priority'=>'high',
            'data' => $notif_array,
            'notification'=>array(
              "body"=>$notif_content
            )
    );
    $fields = json_encode ( $fields );

    $headers = array (
            'Authorization: key=' . $API_KEY,
            'Content-Type: application/json'
    );

    $ch = curl_init ();
    curl_setopt ( $ch, CURLOPT_URL, $url );
    curl_setopt ( $ch, CURLOPT_POST, true );
    curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
    curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt ( $ch, CURLOPT_POSTFIELDS, $fields );

    $result = curl_exec ( $ch );
    echo $result;
    curl_close ( $ch );
}
我已经在firebase控制台上注册了APNs密钥并进行了测试。它工作得很好

我从firebase well收到测试云消息

正如您所知,react native firebase上有几个与通知相关的函数

firebase.notifications().onNotification(notif => console.log(notif))
firebase.notifications().onNotificationDisplayed(notif => console.log(notif))
...
...
firebase.messaging().onMessage(message => console.log(message))
但现在只有onMessage函数在工作

我猜fcm服务器只提供数据而不提供通知

如果有人熟悉php,你能检查一下php代码是否正确吗


谢谢

sendFCM
方法中,未定义变量
$notif\u content
。此外,我知道
数据
已注释掉,但未注释,变量
$notif\u type
也不会被定义


我知道让FCM与iOS一起工作可能有点痛苦,以前我遇到过无效证书的问题,尽管我希望Firebase的弹性更强,因为我已经好几年没有使用它了。

是的,我发现了这个问题,所以我告诉了我们的后端开发人员。他正在做其他的工作,所以我希望在他解决这个问题后,它会起作用。是,如果不再使用
notif\u类型
。我不知道他为什么留着这个,但他知道原因。谢谢你的帮助!