objective-c - 通过 ios 上的 Action 扩展加载 React 本机时,Javascript 似乎没有运行
问题描述
这是来自我的由 Action 扩展启动的视图控制器:
- (void)loadView {
[super loadView];
NSURL *jsCodeLocation;
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
BOOL found = NO;
// Find the item containing the results from the JavaScript preprocessing.
for (NSExtensionItem *item in self.extensionContext.inputItems) {
for (NSItemProvider *itemProvider in item.attachments) {
if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypePropertyList]) {
[itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypePropertyList options:nil completionHandler:^(NSDictionary *dictionary, NSError *error) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
NSDictionary *initialProps = @{@"isActionExtension": @YES, @"preprocessingResults": dictionary[NSExtensionJavaScriptPreprocessingResultsKey]};
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"QCheckoutRN"
initialProperties:initialProps
launchOptions:nil];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
NSLog(@"High Score Button Pressed");
UIViewController *vc = [[UIViewController alloc] init];
vc.view = rootView;
[self presentViewController:vc animated:YES completion:nil];
}];
}];
found = YES;
}
break;
}
if (found) {
break;
}
}
if (!found) {
// We did not find anything
[self doneWithResults:nil];
}
它加载了使用 RN 生成的视图,我看到了 jsx 文件中的按钮,但没有触发任何生命周期方法,无法执行 alert() 并且按钮不会触发操作。
不知道如何调试它,因为 JS 运行时似乎死了,这很奇怪,因为它做了初始渲染。我是不是加载错了?它看起来类似于https://facebook.github.io/react-native/docs/integration-with-existing-apps但他们正在使用一个动作来调用视图,同时我立即加载它。我是 iOS 开发和 Objective-c 的菜鸟,所以如果有人能指出这个问题,它会帮助它运行。
解决方案
推荐阅读
- python - tkinter filedialog.askopenfilename() 窗口不会在 python 3 中关闭
- javascript - javascript/typescript 将外部链接图像保存在 PDF 文件中
- c# - C# WPF - 剪切然后复制整个 Excel 行
- node.js - 如果其他情况下的NodeJS错误-发送后无法设置标头
- java - 使用 Lambda 自动执行匿名函数来自动生成代码
- ios - 如何将在 UITextField 内的任何语言环境中输入的数字转换为 iOS Swift 中的英文数字
- python - 为什么 log(xy) = log(x) + log(y) 在 SymPy 中不起作用?
- linux - 替换字符串中的值
- dart - 飞镖:封闭研究
- java - 在较新版本的 docx4j 中出现损坏问题。我目前正在运行 3.3.6