Flutter.io-是否可以在Flutter中深度链接到Android和iOS?

Flutter.io-是否可以在Flutter中深度链接到Android和iOS?,第1张

Flutter.io-是否可以在Flutter中深度链接到Android和iOS?

您可以为此使用平台渠道。应该不难
您需要在本机代码中添加处理程序,并通过通道将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"),      ),    );  }}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5016678.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-14
下一篇 2022-11-14

发表评论

登录后才能评论

评论列表(0条)

保存