ios - Dose Flutter 同时支持scenedelegate 和sirishortcut 吗?
问题描述
我正在尝试制作一个应用程序以在颤动中使用 siri 快捷方式。但它不起作用。我想要做的是尝试从颤动中显示 iOS 屏幕以使用 MethodChannle 和 ivokeMethod。什么时候可以移动我也注册了siri快捷方式。
在 AppDelegate 中实现 MethodChannel&invokeMethod 的代码。有用。
当我在项目中添加到 SceneDelegate 时,它崩溃并显示这些错误
错误是
[VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: MissingPluginException(No implementation found for method sample/aaa on channel sample/aaa)
#0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:7)
#1 _MyHomePageState._launchNativeScreen (package:flutter_to_ojt/main.dart:36:5)
为什么我添加到 SceneDelegate 是在其中实现 siri 快捷方式代码。我认为这是由 SceneDelegate 引起的,因为当我仅构建 AppDelegate 应用程序时,它可以工作。
让我写下我的代码
·扑
'''class _MyHomePageState extends State<MyHomePage> {
MethodChannel _channel = const MethodChannel('sample/aaa');
Future _launchNativeScreen() async {
await _channel.invokeMethod('sample/aaa');} //MethodChannle to Xcode
enter code here
@override Widget build(BuildContext context) {
var listItem = ["one", "Two", "three"];
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: ListView.builder(itemBuilder: (BuildContext cotext, int index) {
return Container(
decoration: BoxDecoration (
border: Border (
bottom: BorderSide(color: Colors.black38),
),
),
child: ListTile(
leading: const Icon(Icons.arrow_forward_ios_sharp),
title: Text('$index'),
subtitle: Text('&listItem'),
onTap: () { _launchNativeScreen();
print('ここまできてる'); },
));},
itemCount: listItem.length,
),
);}}
'''
・AppDelegate 中的 Xcode
'''
@interface AppDelegate()
@property (nonatomic, strong) UINavigationController *navigationController;
@end
@implementation AppDelegate
FlutterResult _flutterResult;
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
printf("AppDelegate");
[GeneratedPluginRegistrant registerWithRegistry:self];
[self setiOSChannel]; //connect to flutter
Override point for customization after application launch.
return [super application:application didFinishLaunchingWithOptions:launchOptions];}
- (void) setiOSChannel {
printf("setiOSChannel");
FlutterViewController * flutterController =(FlutterViewController*)self.window.rootViewController;
//setup navigation
self.navigationController = [[UINavigationController alloc] initWithRootViewController:flutterController];
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
self.window.rootViewController = self.navigationController;
[self.navigationController setNavigationBarHidden:YES animated:YES];
[self.window makeKeyWindow];
FlutterMethodChannel * methodChannle = [FlutterMethodChannel methodChannelWithName:@"sample/aaa" binaryMessenger:flutterController.binaryMessenger];
[methodChannle setMethodCallHandler:^(FlutterMethodCall * call, FlutterResult result) {
if ([call.method isEqual: @"sample/aaa"] ) {
printf("sample/aaa");
//push遷移ボタンコード
UIStoryboard* storyboard = [UIStoryboard storyboardWithName: @"Main" bundle: nil];
UIViewController* vc = [storyboard instantiateViewControllerWithIdentifier:@"MeasureViewController"];
[self.navigationController pushViewController:vc animated:YES];
printf("push遷移");
}
}];}
'''
・SceneDelegate 中的 Xcode
'''enter code here
@interface SceneDelegate () @end
@implementation SceneDelegate
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions API_AVAILABLE(ios(13.0)){
printf("willConnectToSession");
NSUserActivity * act = [connectionOptions.userActivities.allObjects firstObject];
if (act != nil){
_sirishortcut = YES;
[self scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)act];
}
- (void)sceneDidDisconnect:(UIScene *)scene API_AVAILABLE(ios(13.0)){
}
- (void)sceneDidBecomeActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){
}
- (void)sceneWillResignActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){
}
- (void)sceneWillEnterForeground:(UIScene *)scene API_AVAILABLE(ios(13.0)){
}
- (void)sceneDidEnterBackground:(UIScene *)scene API_AVAILABLE(ios(13.0)){
}
- (void)sceneDidEnterBackground:(UIScene *)scene API_AVAILABLE(ios(13.0)){
}
- (void)sceneDidEnterBackground:(UIScene *)scene API_AVAILABLE(ios(13.0)){
}
enter code here
- (void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivity API_AVAILABLE(ios(13.0)){
//storyboard取得
UIStoryboard* storyboard = [UIStoryboard storyboardWithName: @"Main" bundle: nil];
//storyboardID指定
UIViewController* vc = [storyboard instantiateViewControllerWithIdentifier:@"MeasureViewController"];
//画面遷移のアニメーションを設定
vc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
//UINavigationControllerに向けてモーダル遷移
//[[self window presentViewController:nc animated:YES completion:nil];
//モーダル遷移
[self.window.rootViewController presentViewController:vc animated:YES completion: nil];}'''
・信息列表中的 Xcode
'''enter code here
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN""http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneDelegateClassName</key>
<string>SceneDelegate</string>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
</dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>flutter_to_ojt</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSUserActivityTypes</key>
<array>
<string>DoscaleIntent</string>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
你怎么看?
解决方案
推荐阅读
- html - 电话输入自动填充删除国际前缀
- mongodb - 如何在 Windows 上设置 MongoDB 日志轮换?
- java - 尝试调用虚拟方法 'void androidx.recyclerview.widget.RecyclerView.setAdapter
- c++ - 不同的输出取决于我是否打印返回值
- r - 如何在闪亮服务器的反应函数中添加多个输入变量?
- python - 从 index.ts 触发导出可执行脚本命令
- pandas - 在熊猫中单独计算时间增量
- f# - 如何通过在 F# 中为每个惰性对象创建值来转换其中包含惰性对象的异构数组(无反射)
- spring - 创建自己的配置类
- javascript - 访问 javascript 返回函数的属性时遇到问题