栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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"),      ),    );  }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/406993.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号