use*_*752 5 objective-c dart flutter
所需的输出如下所示,
如何使用颤振以编程方式在点击事件上显示这一点(如果可能的话,即使使用本机代码),如果有人能展示一个例子,我们真的很感激。如果没有直接的方法,那么使用 MethodChannel 的平台特定示例也非常受欢迎。本机代码示例必须在目标 C 中。
此外,我尝试使用flutter_to_airplay但项目无法运行,并且还具有在此上下文中不需要的其他功能,需要的只是显示 Airplay 面板。
(M123本机代码的答案完全不起作用)
下面是如何在 Objective c 中打开 AirPlayPanel 的示例。
\n首先您必须创建一个频道。开始与本机代码通信。
\n\n\n单个应用程序中使用的所有频道名称必须是唯一的;使用唯一的 \xe2\x80\x98 域前缀为频道名称添加前缀\n
\n
static const platform = const MethodChannel(\'stack.M123.dev/airplay\');\nRun Code Online (Sandbox Code Playgroud)\n然后您必须调用方法通道上的方法。
\n Future<void> _openAirPlay() async {\n try {\n await platform.invokeMethod(\'openAirPlay\');\n } on PlatformException catch (e) {\n print(\'error\');\n }\n\n\n }\nRun Code Online (Sandbox Code Playgroud)\n现在颤振部分已经完成。
\n首先你必须添加对 swift 的支持。为此,使用 XCode 打开 flutter 根目录中的 ios 文件夹。
\nExpand Runner > Runner in the Project navigator.\nRun Code Online (Sandbox Code Playgroud)\n打开项目导航器中 Runner > Runner 下的 AppDelegate.m。
\n创建一个 FlutterMethodChannel 并在应用程序 didFinishLaunchingWithOptions: 方法中添加一个处理程序。确保使用与 Flutter 客户端使用的通道名称相同的通道名称。
\n#import <Flutter/Flutter.h>\n#import "GeneratedPluginRegistrant.h"\n\n@implementation AppDelegate\n- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {\n FlutterViewController* controller = (FlutterViewController*)self.window.rootViewController;\n\n FlutterMethodChannel* airPlayChannel= [FlutterMethodChannel\n methodChannelWithName:@"stack.M123.dev/airplay"\n binaryMessenger:controller.binaryMessenger];\n\n [airPlayChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {\n // Note: this method is invoked on the UI thread.\n if ([@"getBatteryLevel" isEqualToString:call.method]) {\nint returnValue = [weakSelf openAirPlay];\n\n\n result(@(returnValue));\n\n }];\n\n [GeneratedPluginRegistrant registerWithRegistry:self];\n return [super application:application didFinishLaunchingWithOptions:launchOptions];\n}\nRun Code Online (Sandbox Code Playgroud)\n在 AppDelegate 类中添加该方法,位于 @end 之前
\n- (int)openAirPlay {\n //Open air play\n return (int)(100);\n \n}\nRun Code Online (Sandbox Code Playgroud)\nDisalimer:我不是 IOS 开发人员,因此这些步骤大多是理论性的。\n我正在遵循 Flutter 的官方指南。可以在此处找到完整内容。
\n| 归档时间: |
|
| 查看次数: |
297 次 |
| 最近记录: |