firebase-messaging - Fatal: failed to find callback

前端 未结 4 886
情话喂你
情话喂你 2021-01-01 14:11

I\'m trying to use FCM messaging and keep getting this error.

E/FlutterFcmService( 3684): Fatal: failed to find callback

Below is the code I\'ve

4条回答
  •  天命终不由人
    2021-01-01 14:33

    You should declare a backgroundMessageHandler function that is outside a class or as a static function, in order to be reached from outside, and then you pass this function to fbm.configure:

    Future myBackgroundMessageHandler(Map message) {
      print('on background $message');
    }
    
    fbm.configure(
          onMessage: (msg) {
            print(msg);
            return;
          },
          onLaunch: (msg) {
            print(msg);
            return;
          },
          onResume: (msg) {
            print(msg);
            return;
          },
          onBackgroundMessage: myBackgroundMessageHandler
    );
    

    Also open your_project_folder/android/app/source/AndroidManifest.xml and paste this XML code after existing intent-filter code of your main Activity:

    
        
        
    
    

    The result will be similar to the following code:

    
                
                    
                    
                
                
                    
                    
                
    
    

提交回复
热议问题