当前位置: 首页 > news >正文

网站建设代理成本如何做好网页设计

网站建设代理成本,如何做好网页设计,湘潭网站公司,网站后台地址破解flutter开发实战-MethodChannel实现flutter与iOS双向通信 最近开发中需要iOS与flutter实现通信#xff0c;这里使用的MethodChannel 如果需要flutter与Android实现双向通信#xff0c;请看 https://blog.csdn.net/gloryFlow/article/details/132218837 这部分与https://bl…flutter开发实战-MethodChannel实现flutter与iOS双向通信 最近开发中需要iOS与flutter实现通信这里使用的MethodChannel 如果需要flutter与Android实现双向通信请看 https://blog.csdn.net/gloryFlow/article/details/132218837 这部分与https://blog.csdn.net/gloryFlow/article/details/132218837中的一致这里实现一下iOS端的MethodChannel设置。 一、MethodChannel MethodChannel用于传递方法调用(method invocation)。 通道的客户端和宿主端通过传递给通道构造函数的通道名称进行连接 一个应用中所使用的所有通道名称必须是唯一的 使用唯一的域前缀为通道名称添加前缀比如samples.flutter.dev/battery 官网 https://flutter.cn/docs/development/platform-integration/platform-channels 二、在flutter端实现MethodChannel 我们需要创建一个名字为samples.flutter.dev/test的通道名称。 通过invokeNativeMethod与setMethodCallHandler来实现 invokeNativeMethod调用Android端的代码 setMethodCallHandler设置方法回调用于接收Android端的参数 代码如下 import package:flutter/services.dart;//MethodChannel const methodChannel const MethodChannel(samples.flutter.dev/test);class FlutterMethodChannel {/** MethodChannel* 在方法通道上调用方法invokeMethod* methodName 方法名称* params 发送给原生的参数* return数据 原生发给Flutter的参数*/static FutureMap invokeNativeMethod(String methodName,[Map? params]) async {var res;try {if (params null) {res await methodChannel.invokeMethod($methodName);} else {res await methodChannel.invokeMethod($methodName, params);}} catch (e) {res {Failed: e.toString()};}return res;}/** MethodChannel* 接收methodHandler* methodName 方法名称* params 发送给原生的参数* return数据 原生发给Flutter的参数*/static void methodHandlerListener(Futuredynamic Function(MethodCall call)? handler) {methodChannel.setMethodCallHandler(handler);} }使用该MethodChannel我们需要使用MethodChannel 使用代码如下 overridevoid initState() {// TODO: implement initStatesuper.initState();setMethodHandle();}void setMethodHandle() {FlutterMethodChannel.methodHandlerListener((call) {print(methodHandlerListener call:${call.toString()});if (methodToFlutter call.method) {print(methodToFlutter arg:${call.arguments});}return Future.value(message from flutter);});}Futurevoid invokeNativeMethod() async {var result await FlutterMethodChannel.invokeNativeMethod(methodTest, {param:params from flutter});print(invokeNativeMethod result:${result.toString()});}void testButtonTouched() {invokeNativeMethod();}overridevoid dispose() {// TODO: implement disposesuper.dispose();}这里我们处理了方法methodToFlutter来接收iOS端的传参数调用同时处理后我们将结果message from flutter返回给iOS端。 我们调用iOS端的方法methodTest并且传参获取iOS端传回的结果。 三、在iOS端实现MethodChannel 在iOS中同样我们实现了MethodChannel。 iOS实现MethodChannel需要实现FlutterPlugin实现registerWithRegistrar 我这里命名一个SDFlutterMethodChannelPlugin继承NSObject通过实现registerWithRegistrar方法 (void)registerWithRegistrar:(NSObjectFlutterPluginRegistrar*)registrar {FlutterMethodChannel *methodChannel [FlutterMethodChannel methodChannelWithName:kFlutterMethodChannelName binaryMessenger:[registrar messenger] codec:[FlutterStandardMethodCodec sharedInstance]];SDFlutterMethodChannelPlugin *instance [[SDFlutterMethodChannelPlugin alloc] initWithMethodChannel:methodChannel];// 将插件注册为来自Dart端的传入方法调用的接收者 在指定的“ FlutterMethodChannel”上。[registrar addMethodCallDelegate:instance channel:methodChannel]; }同样在插件SDFlutterMethodChannelPlugin中设置setMethodCallHandler及调用Flutter的方法 例如 __weak typeof(self) weakSelf self;[self.methodChannel setMethodCallHandler:^(FlutterMethodCall *call, FlutterResult result) {[weakSelf handleMethodCall:call result:result];}];通过handleMethodCall可以处理方法methodTest处理接收来自flutter的参数处理后并将结果返回给flutter。 整体代码如下 SDFlutterMethodChannelPlugin.h #import Foundation/Foundation.h #import Flutter/Flutter.hclass SDFlutterMethodChannelPlugin;typedef void (^SDFlutterMethodChannelPluginCompletionBlock)(SDFlutterMethodChannelPlugin *plugin);interface SDFlutterMethodChannelPlugin : NSObjectFlutterPlugin- (instancetype)initWithMethodChannel:(FlutterMethodChannel *)methodChannel;endSDFlutterMethodChannelPlugin.m #define kFlutterMethodChannelName samples.flutter.dev/testinterface SDFlutterMethodChannelPlugin ()FlutterStreamHandlerproperty (nonatomic, strong) FlutterMethodChannel *methodChannel;property (nonatomic, strong) NSTimer *sendMessageTimer;endimplementation SDFlutterMethodChannelPlugin- (instancetype)initWithMethodChannel:(FlutterMethodChannel *)methodChannel {self [super init];if (self) {self.flutterBridgeConfig [[DFFlutterBridgeConfig alloc] init];self.methodChannel methodChannel;__weak typeof(self) weakSelf self;[self.methodChannel setMethodCallHandler:^(FlutterMethodCall *call, FlutterResult result) {[weakSelf handleMethodCall:call result:result];}];[self startSendMessageTimer];}return self; } (void)registerWithRegistrar:(NSObjectFlutterPluginRegistrar*)registrar {FlutterMethodChannel *methodChannel [FlutterMethodChannel methodChannelWithName:kFlutterMethodChannelName binaryMessenger:[registrar messenger] codec:[FlutterStandardMethodCodec sharedInstance]];SDFlutterMethodChannelPlugin *instance [[SDFlutterMethodChannelPlugin alloc] initWithMethodChannel:methodChannel];// 将插件注册为来自Dart端的传入方法调用的接收者 在指定的“ FlutterMethodChannel”上。[registrar addMethodCallDelegate:instance channel:methodChannel]; }#pragma mark - FlutterPlugin协议方法 - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {NSLog(config handleMethodChannel callmethod:%,params:%,result:%, call.method, call.arguments, result);// 没有处理需要单独处理NSString *methodcall.method;if ([method isEqualToString:methodTest]) {NSLog(flutter 调用到了 ios test);NSMutableDictionary *dic [NSMutableDictionary dictionary];[dic setObject:result.success 返回给flutter的数据 forKey:message];[dic setObject: [NSNumber numberWithInt:200] forKey:code];result(dic);} else if ([method isEqualToString:test2]) {NSLog(flutter 调用到了 ios test2);result(YES);} else {result(FlutterMethodNotImplemented);} }#pragma mark - 开启定时器 - (void)sendMessageTimerAction {// 开启[self.methodChannel invokeMethod:methodToFlutter arguments:Params from Android]; }/**开启定时器 */ - (void)startSendMessageTimer {if (_sendMessageTimer) {return;}//开始其实就是开始定时器_sendMessageTimer [NSTimer timerWithTimeInterval:6 target:self selector:selector(sendMessageTimerAction) userInfo:nil repeats:YES];//加到runloop[[NSRunLoop currentRunLoop] addTimer:_sendMessageTimer forMode:NSRunLoopCommonModes]; }/**结束定时器*/ - (void)stopSendMessageTimer {//暂停其实就是销毁计时器[_sendMessageTimer invalidate];_sendMessageTimer nil; }end在iOS中需要在AppDelegate中设置在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法中实现 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {[SDFlutterMethodChannelPlugin registerWithRegistrar:[(id)[SDWeakProxy proxyWithTarget:self] registrarForPlugin:SDFlutterMethodChannelPlugin]];return YES; } 我们在iOS代码中实现MethodChanel通过定时器NSTimer定时调用方法methodToFlutter将参数传递给Flutter端。通过在iOS端setMethodCallHandler根据方法methodTest处理接收来自flutter的参数处理后并将结果返回给flutter。 四、小结 flutter开发实战-MethodChannel实现flutter与iOS双向通信。实现MethodChannel在flutter端与iOS端实现相互通信功能。 https://blog.csdn.net/gloryFlow/article/details/132240415 学习记录每天不停进步。
http://www.w-s-a.com/news/104251/

相关文章:

  • 电子商务网站建设报告范文单位做网站怎么做
  • 优质的外国网站qq小程序在哪里打开
  • 商务网站建设与推广实训报告免费素材网站无水印
  • 外贸站seoapp开发公司历程概述
  • 沈阳网站推广¥做下拉去118cr陶瓷企业 瓷砖地板公司网站建设
  • 医院网站官方微信精神文明建设我做服装设计师的 求推荐资源网站
  • 微信网站建设需要那些资料昆明cms模板建站
  • 安庆网站建设兼职中企动力是500强吗
  • 网站排名优化技巧基于网站的网络营销方法有哪些
  • 摄影素材网站做知识问答的网站
  • 中小企业网站建设济南兴田德润电话门店管理系统软件排行
  • 昆明工程建设信息网站柳州网站建设公司哪家好
  • 如何分析网站关键词北京门户网站网址
  • 做网站与做游戏那个好网站域名怎么起
  • 有没有做cad单的网站银行网站建设方案视频
  • 和各大网站做视频的工作高校网站群管理系统
  • 中国建设人才服务信息网是正规网站怎么注销自己名下的公司
  • 网站开发新型技术那些网站做任务领q币
  • 海口手机网站建设wordpress微支付宝
  • 做公司网站需要几天深圳自定义网站开发
  • 做网站学多长时间可以学会推广软件公司
  • 网络网站设计培训长沙建站模板大全
  • 站群搭建移动端处理器天梯图
  • 岳池发展建设集团有限公司门户网站湛江seo咨询
  • 手机网站工具关键词排名是什么意思
  • 游民星空是谁做的网站沈阳网站托管公司
  • 做网站搭建需要什么人vs2017移动网站开发
  • 购物网站开发需要什么技术怎么查看网站是否备案
  • 学做电商那个网站好网站建设投票主题
  • 中卫网站推广网络营销毕业设计做网站大小有什么要求