【发布时间】:2021-06-21 21:50:27
【问题描述】:
我在使用 FCM 和 iOS 测试飞行构建时遇到了问题(我假设应用商店发布版本也是如此)。推送通知在使用本地物理测试 iphone 11 构建 Flutter 应用程序时起作用。设备注册,我们将令牌存储在数据库中。当我随后向设备发送推送时,它工作正常。但是当我存档应用程序并将其分发到 testflight 通知停止工作。我从我们的数据库中删除令牌,删除测试本地构建,然后安装新发布的 testflight 应用程序,该应用程序在打开时会在数据库中注册一个令牌。在发送测试消息时,我会收到此错误
消息无法传送到由
Although the token is syntactically correct, it is not known to the Firebase
project you are using. This could have the following reasons:
- The token has been unregistered from the project. This can happen when a user
has logged out from the application on the given client, or if they have
uninstalled or re-installed the application.
- The token has been registered to a different Firebase project than the project
you are using to send the message. A common reason for this is when you work
with different application environments and are sending a message from one
environment to a device in another environment.
我不认为这是第一种情况,因为我们在代码库中的任何地方都没有调用来使该令牌无效。
我们认为这与第二种情况有关。我们的一位项目经理在所有者之间转移了项目。
值得注意的是,Android 无处不在,本地物理设备构建和应用商店的内部测试轨道。
我正在使用 kreait/firebase-php 包发送测试推送通知,这是我发送通知的代码。
public function __construct()
{
$this->service = (new Factory)
->withServiceAccount(storage_path('app/google-service-account.json'));
$this->messaging = $this->service->createMessaging();
}
public function setReminder($msg, $title)
{
$body = Str::limit($msg, 400);
$this->payload = [
'notification' => [
'title' => $title,
'body' => $body,
],
'android' => [
'priority' => 'HIGH',
'notification' => [
'title' => $title,
'body' => $body,
'click_action' => 'FLUTTER_NOTIFICATION_CLICK',
'color' => '#33b0b3',
],
],
'apns' => [
'headers' => [
'apns-priority' => '10',
'apns-collapse-id' => 'reminder',
],
'payload' => [
'aps' => [
'alert' => [
'title' => $title,
'body' => $body,
],
'sound' => 'default',
'content-available' => 1,
],
],
],
];
}
public function send(string $device)
{
$this->payload['token'] = $device;
return $this->messaging
->send($this->payload);
}
然后这样调用:
Fcm::setReminder(
trans('user.push.reminders.module_part2_reminder'),
'Pulse Reminder');
Fcm::send($device->token);
【问题讨论】:
标签: ios flutter firebase-cloud-messaging