Swift native code returns iOS version instead of bool

Viewed 113

I am trying to return a boolean value from Swift native code however instead of returning the boolean it returns a String which contains the iOS version of my device and shows me the error -

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

This is where my dart code is causing the problem

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

This is the iOS Swift native code :

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

This is what I am calling to print the bool -

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

Turns out I was calling it incorrectly and it was returning the version number due to the default Flutter AppDelegate template -

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)
  }
}
Related