2017-07-27 31 views

回答

2

您可以使用platform channel。它不應該很難。您需要在本地代碼中添加處理程序,並通過通道重定向url以晃動代碼。 實施例爲iOS:

@implementation AppDelegate 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    [GeneratedPluginRegistrant registerWithRegistry:self]; 
    FlutterViewController *controller = (FlutterViewController*)self.window.rootViewController; 

    self.urlChannel = [FlutterMethodChannel methodChannelWithName:@"com.myproject/url" binaryMessenger:controller]; 

    return [super application:application didFinishLaunchingWithOptions:launchOptions]; 
} 

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{ 

    [self.urlChannel invokeMethod:@"openURL" 
         arguments:@{@"url" : url.absoluteString}]; 

    return true; 
} 

@end 

和基本撲代碼:

class _MyHomePageState extends State<MyHomePage> { 

    final MethodChannel channel = const MethodChannel("com.myproject/url"); 

    String _url; 

    @override 
    initState() { 
    super.initState(); 

    channel.setMethodCallHandler((MethodCall call) async { 
     debugPrint("setMethodCallHandler call = $call"); 

     if (call.method == "openURL") { 
     setState(() => _url = call.arguments["url"]); 
     } 
    }); 
    } 


    @override 
    Widget build(BuildContext context) { 
    return new Scaffold(
     appBar: new AppBar(
     title: new Text(_url ?? "No URL"), 
    ), 
    ); 
    } 
} 
相關問題