我正在开发一个应用程序,并已将FCM发送到Android设备的通知,但目前在发送到iOS设备时遇到问题。
我已按照列出的here进行操作,其中还包括列出的here的步骤。
这是我拥有的适用于Android设备的FCM SDK代码:
// This assumes that you have placed the Firebase credentials in the same directory
// as this PHP file.
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/google-service-account.json');
// get our Firebase account loaded
$firebase = (new Firebase\Factory())
->withServiceAccount($serviceAccount)
->create();
// create a message
$messaging = $firebase->getMessaging();
// Creating a notification
$notification = Notification::fromArray([
'title' => $title,
'body' => $body,
]);
$data = [
'click_action' => 'FLUTTER_NOTIFICATION_CLICK',
'fromid' => $fromid,
];
// Compose the message; notification + device token
$message = CloudMessage::withTarget('token', $deviceToken)
->withNotification($notification)
->withData($data);
// validate the message
try {
$messaging->validate($message);
} catch (InvalidMessage $e){
print_r($e->errors());
exit;
}
// send message
$report = $messaging->send($message);
我尝试通过Firebase控制台并使用FCM SDK发送消息;两者均未导致通知出现在iOS设备上。控制台没有给我任何反馈,但是SDK给了我一个错误:
致命错误:未捕获的GuzzleHttp \ Exception \ ClientException:客户端错误:POST https://fcm.googleapis.com/v1/projects/apwt-app1/messages:send
导致了401 Unauthorized
响应:
{
“错误”:{
“代码”:401,
“ message”:“来自APNS或Web Push Service的身份验证错误”,
“ status”:“ UNAUTHENTICATE(已截断...)
在/var/www/vhosts/globalsups/composer/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113