适用于 iOS 的 Firebase 云消息传递适用于本地构建,但不适用于 Testflight

时间:2021-03-25 05:39:23

标签: ios flutter firebase-cloud-messaging

我遇到了 FCM 和 iOS testflight 版本的问题(我假设应用商店版本也是如此)。使用本地物理测试 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);

1 个答案:

答案 0 :(得分:0)

默认情况下,在本地设备中启动的应用程序使用 <?php $member_group_terms = get_terms( 'categoria' ); ?> <?php foreach ( $member_group_terms as $member_group_term ) { $member_group_query = new WP_Query( array( 'post_type' => 'documento', 'tax_query' => array( array( 'taxonomy' => 'categoria', 'field' => 'slug', 'terms' => array( $member_group_term->slug ), 'operator' => 'IN' ) ) ) ); ?> <h2><?php echo $member_group_term->name; ?></h2> <ul> <?php if ( $member_group_query->have_posts() ) : while ( $member_group_query->have_posts() ) : $member_group_query->the_post(); ?> <li><?php echo the_title(); ?></li> <?php endwhile; endif; ?> </ul> <?php // Reset things, for good measure $member_group_query = null; wp_reset_postdata(); } ?> 作为权利。这意味着使用苹果沙箱和相关令牌。

虽然使用testflight会自动使用development:所以你需要切换服务器配置以使用不同的证书和服务器