【问题标题】:Swift native code returns iOS version instead of boolSwift 本机代码返回 iOS 版本而不是 bool
【发布时间】:2021-05-12 21:34:59
【问题描述】:

我正在尝试从 Swift 本机代码返回一个布尔值,但是它没有返回布尔值,而是返回一个包含我的设备的 iOS 版本并向我显示错误的字符串 -

Unhandled Exception: type 'String' is not a subtype of type 'bool' in type cast

这是我的飞镖代码导致问题的地方

static Future<bool> isLoaded() async {
    return _channel.invokeMethod("isLoaded");
  }

这是 iOS Swift 原生代码:

case "isLoaded":    
 result(self.p.isContentReady)  //returns a bool true or false          
   break;

这就是我要打印的布尔值 -

print(await Tapjoy.isLoaded()) //returns iOS 14.4 as a 'String' instead of true/false

【问题讨论】:

    标签: ios swift flutter dart


    【解决方案1】:

    原来我调用不正确,由于默认的 Flutter AppDelegate 模板,它返回了版本号 -

    public class SwiftPlugin: NSObject, FlutterPlugin {
      public static func register(with registrar: FlutterPluginRegistrar) {
        let channel = FlutterMethodChannel(name: "flutter", binaryMessenger: registrar.messenger())
        let instance = SwiftPlugin()
        registrar.addMethodCallDelegate(instance, channel: channel)
      }
    
      public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
        result("iOS " + UIDevice.current.systemVersion)
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-18
      • 2016-10-23
      • 2018-03-23
      • 1970-01-01
      • 2020-09-11
      • 2016-11-09
      • 2016-05-28
      相关资源
      最近更新 更多