【问题标题】:Firebase cloud messaging for iOS works on local build but not for Testflight适用于 iOS 的 Firebase 云消息传递适用于本地构建,但不适用于 Testflight
【发布时间】: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


    【解决方案1】:

    默认情况下,在本地设备中启动的应用程序使用development 作为权利。这意味着使用苹果沙箱和相关令牌。

    使用testflight时自动使用production:所以需要切换服务器配置使用不同的证书和服务器

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-25
      • 2019-06-12
      • 1970-01-01
      • 1970-01-01
      • 2016-04-19
      • 2016-04-05
      相关资源
      最近更新 更多