代码之家  ›  专栏  ›  技术社区  ›  Zufar Muhamadeev

Flutter firebase消息,ios应用程序不接收令牌

  •  0
  • Zufar Muhamadeev  · 技术社区  · 7 年前

    firebase messaging plugin 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 回复  |  直到 7 年前
        1
  •  3
  •   Zufar Muhamadeev    7 年前

    当我把firebase代码移到 TestApp main.dart 是fcm代码的错误位置。我把它放进去了 initState

        2
  •  0
  •   Feu    7 年前

    截至2018年10月11日 getToken 实现有问题(参见问题 17699 20378

    有一个 pull request

    盖托肯 ,我建议听听 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());
    }