iOS 推送通知仅在真实设备上的调试模式下有效,但从 App Store 下载时无效

问题描述 投票:0回答:1

我有一个项目,使用云功能根据用户选择的主题发送推送通知。

用户订阅主题:

 await FirebaseMessaging.instance.subscribeToTopic(('mytopic'));

然后是我的云功能:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const fcm = admin.messaging();

      var payload = {
            "notification": {
                "title": msgData.name,
                "body": msgData.title,
                "click_action": 'FLUTTER_NOTIFICATION_CLICK',
                "android_channel_id": "my_channel_id",
            },
    
             "data": {
               
                "content": msgData.content,
                "title": msgData.title,        
            }
        };
        return fcm.sendToTopic("/topics/" + 'mytopic', payload);

在 Android 上它可以 100% 运行。无论是在调试中还是在真实设备上以及从 Play 商店下载时。

在真实的 iOS 设备上,它只能在调试模式下工作。我从 App Store 下载时没有收到任何通知

我在真正的 iOS 设备上启动时注意到此错误,但不确定这意味着什么 :

[FirebaseMessaging][I-FCM002022] APNS device token not set before retrieving FCM Token for Sender ID '123456789'. Notifications to this FCM Token will not be delivered over APNS.Be sure to re-retrieve the FCM token once the APNS device token is set.

另请参阅 Xcode 屏幕截图:

enter image description here

我尝试将以下内容添加到 AppDelegate.swift 以及类似问题中提到的:

import UIKit
import Flutter


@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    application.registerForRemoteNotifications()//I ADDED THIS TO ATTEMPT FOR iOS push messaging to work in Release/Production Mode 
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

我确实在代码中请求许可。如果我想在真实设备上接收来自应用程序的通知,我会收到提示:

  NotificationSettings settings =
        await FirebaseMessaging.instance.requestPermission(
      alert: true,
      badge: true,
      provisional: false,
      sound: true,
    );

    if (settings.authorizationStatus == AuthorizationStatus.authorized) {
      print('User granted permission');
      String? token = await FirebaseMessaging.instance.getToken();
      print("The token is " + token!);
      // For handling the received notifications

    } else {
      print('User declined or has not accepted permission');
    }

    /// Update the iOS foreground notification presentation options to allow
    /// heads up notifications.
    await FirebaseMessaging.instance
        .setForegroundNotificationPresentationOptions(
      alert: true,
      badge: true,
      sound: true,
    );

开发者帐户的一些屏幕截图:

enter image description here enter image description here enter image description here

我一直在努力解决这个问题。如果有人可以帮忙的话。如果可以解决问题,我会添加更多信息。谢谢你

ios xcode flutter google-cloud-functions firebase-cloud-messaging
1个回答
0
投票

我也经历过同样的事情。我忘记关闭专注模式、请勿打扰和睡眠模式。关机后就正常了

对焦模式

请勿打扰和睡眠模式

© www.soinside.com 2019 - 2024. All rights reserved.