firebase - 使用 FCM 向 iOS 设备推送通知时遇到问题
问题描述
我正在开发一个应用程序,并已让 FCM 将通知发送到 Android 设备,但目前在发送到 iOS 设备时遇到问题。
我已按照此处列出的步骤执行此操作,其中还包括此处列出的步骤。
这是我拥有的适用于 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,“消息”:“来自 APNS 或 Web 推送服务的身份验证错误”,“状态”:“ /var/www/vhosts/globalsups/composer/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113 中的 UNAUTHENTICATE(截断...)
解决方案
推荐阅读
- postgresql - 如何计算postgresql中的百分比(%)
- java - 如何让 micronaut 为 Value.Immutable 类生成 OpenAPI 模式属性?
- google-chrome - 引用 SVG 的不同颜色的过渡
- neo4j - 无法通过带有 UNION 的 CALL 汇总总计
- amazon-web-services - 如何解决错误:Terraform 中的“不得引用参数名称”?
- rust - 理解 &* 以访问 Rust Arc
- python - 在 Python 中为模块(不是类)中的函数实现类型?
- c - C中的堆栈和pop()函数
- linux - docker-in-docker 使用内存还是磁盘?
- linux - Zenity 以 root 身份运行时不显示通知