扑火的Firebase消息传递,iOS应用程序未收到令牌

时间:2018-10-10 21:23:00

标签: ios firebase dart flutter firebase-cloud-messaging

我已在Flutter应用中配置了Firebase消息传递。它使用firebase messaging plugin。我已经根据自述文件的“ iOS集成”部分进行了配置。 Firebase已在main.dart

中启动
void main() async {
  final FirebaseMessaging _firebaseMessaging = new FirebaseMessaging();
  _firebaseMessaging.requestNotificationPermissions();
  _firebaseMessaging.configure(onMessage: processMessage,
      onLaunch: processLaunch,
      onResume: processResume);
  String token = await _firebaseMessaging.getToken();
  print("fcm token is: $token");
  runApp(TestApp());
}

Future<dynamic> processMessage(Map<String, dynamic> map) async {
  print("received message:");
  print(map);
}

Future<dynamic> processLaunch(Map<String, dynamic> map) async {
  print("processing launch");
  print(map);
}

Future<dynamic> processResume(Map<String, dynamic> map) async {
  print("processing resume");
  print(map);
}

问题是应用程序未收到令牌。因此,我将应用程序部署到物理设备,应用程序启动,但是没有看到与fcm相关的任何输出,并且未显示ui。我在IDEA中看到以下日志:

5.10.0 - [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) to your application initialization. Read more: .
5.10.0 - [Firebase/Messaging][I-FCM001000] FIRMessaging Remote Notifications proxy enabled, will swizzle remote notification receiver handlers. If you'd prefer to manually integrate Firebase Messaging, add "FirebaseAppDelegateProxyEnabled" to your Info.plist, and set it to NO. Follow the instructions at:
https://firebase.google.com/docs/cloud-messaging/ios/client#method_swizzling_in_firebase_messaging

哪里有问题?

2 个答案:

答案 0 :(得分:2)

当我将Firebase代码移至TestApp时,它开始起作用,似乎main.dart对于fcm代码是错误的位置。我将其放在initState内。

答案 1 :(得分:0)

截至2018年10月11日,getToken实现存在错误(请参阅问题1769920378)。

有一个pull request可以对其进行修复,但仍未解决。

现在,为了避免getToken出现问题,我建议听onTokenRefresh(这就是我的工作)。

我没有测试下面的代码,但这只是您如何修改代码的示例。

String _token;

void main() async {
  final FirebaseMessaging _firebaseMessaging = new FirebaseMessaging();
  _firebaseMessaging.requestNotificationPermissions();

  Stream<String> fcmStream = _firebaseMessaging.onTokenRefresh;
  fcmStream.listen((token) {
    // saveToken(token);
    print("fcm token is: $token");
    _token = token;     
  });

  _firebaseMessaging.configure(onMessage: processMessage,
      onLaunch: processLaunch,
      onResume: processResume);

  runApp(TestApp());
}