无法使用 fcm 令牌 firebase 向 ios 发送推送通知
unable to send push notification to ios using fcm token firebase
我尝试使用 firebase 通知控制台发送通知,它工作正常,但使用代码时会抛出错误
{"multicast_id":469219618584251399,"成功":0,"失败":1,"canonical_ids":0,"结果":[{"error":"InvalidRegistration"}]}
我的代码:-
<?php
define('API_ACCESS_KEY','Server key');
'to' => $token, //single token
'notification' => $notification,
'data' => $extraNotificationData
];
$headers = [
'Authorization: key=API_ACCESS_KEY',
'Content-Type: application/json'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$fcmUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fcmNotification));
$result = curl_exec($ch);
curl_close($ch);
echo $result;
我已经解决了。 iOS 端生成的令牌是错误的。
以下是之前使用的代码:-
UIDevice.current.identifierForVendor!.uuidString
现在我正在使用下面的代码:-
Messaging.messaging().fcmToken
我尝试使用 firebase 通知控制台发送通知,它工作正常,但使用代码时会抛出错误 {"multicast_id":469219618584251399,"成功":0,"失败":1,"canonical_ids":0,"结果":[{"error":"InvalidRegistration"}]} 我的代码:-
<?php
define('API_ACCESS_KEY','Server key');
'to' => $token, //single token
'notification' => $notification,
'data' => $extraNotificationData
];
$headers = [
'Authorization: key=API_ACCESS_KEY',
'Content-Type: application/json'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$fcmUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fcmNotification));
$result = curl_exec($ch);
curl_close($ch);
echo $result;
我已经解决了。 iOS 端生成的令牌是错误的。
以下是之前使用的代码:-
UIDevice.current.identifierForVendor!.uuidString
现在我正在使用下面的代码:-
Messaging.messaging().fcmToken