美文网首页
Flutter踩坑记录-iOS端 fluwx无法收到回调

Flutter踩坑记录-iOS端 fluwx无法收到回调

作者: 剧文轩 | 来源:发表于2020-08-27 18:03 被阅读0次

    工程背景

    iOS项目嵌套Flutter工程,iOS调用Flutter项目中的fluwx库进行WX登录 -> 注册 -> 返回:token到iOS端

    ⚠️坑:微信登录返回 flutter没有监听到回调

    iOS代码
    
    @objc func pushFlutter(){
            // 创建flutter engine
            let engine = FlutterEngine(name: "yu.FlutterEngine");
            engine.run(withEntrypoint: nil);
            
            
            // 创建通道
            let channel = FlutterMethodChannel(name: "test.ju.flutter", binaryMessenger: engine.binaryMessenger);
            // 发送消息
            channel.invokeMethod("goWxLogin", arguments: nil);
        }
    

    Flutter代码

            print("微信登录");
            // 微信注册
            await registerWxApi(
                appId: "wxappid",
                doOnAndroid: true,
                doOnIOS: true,
                universalLink: "https://universalLink.hp");
            //发送登录
            await sendWeChatAuth(scope: "snsapi_userinfo").then((data) {
              print('跳转成功');
            });
            //监听回调
            weChatResponseEventHandler.listen((event) {
              print("监听回调");
              print(event);
            });
    

    手机进行操作:微信登录、确定、返回。操作无异常
    但是没有收到回调
    发现控制台打印

    flutter: 微信登录
    flutter: 跳转成功
    
    Could not register as server for FlutterObservatoryPublisher. Check your network settings and relaunch the application.
    
    

    错误提示:Could not register as server for FlutterObservatoryPublisher. Check your network settings and relaunch the application.

    问题原因:

    微信登录返回的回调只是在iOS端并没有传递给Flutter

    解决方法

    @UIApplicationMain
    class AppDelegate: FlutterAppDelegate {
    
        override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
            // Override point for customization after application launch.
            return super.application(application, didFinishLaunchingWithOptions: launchOptions);
        }
    
    }
    

    AppDelegate继承于FlutterAppDelegate 重新方法。问题解决

    flutter: 监听回调
    

    相关文章

      网友评论

          本文标题:Flutter踩坑记录-iOS端 fluwx无法收到回调

          本文链接:https://www.haomeiwen.com/subject/mzzqsktx.html