【发布时间】:2019-01-17 17:38:53
【问题描述】:
需要一些关于如何让RNN 与react-native-siri-shortcut 合作的指导。
如果我的帖子过于冗长,请多多包涵,因为我是 xCode 和 objective C 的菜鸟,所以不要错过任何内容。
所以我在尝试让这 2 个库一起工作时遇到了几个问题/问题:
1。使用RCTRootView 设置initialProperties
react-native-siri-shortcuts 在AppDelegate.m 中设置应用程序如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
// Check if the app launched with any shortcuts
BOOL launchedFromShortcut = [launchOptions objectForKey:@"UIApplicationLaunchOptionsUserActivityDictionaryKey"] != nil;
//Add a boolean to the initialProperties to let the app know you got the initial shortcut
NSDictionary *initialProperties = @{ @"launchedFromShortcut":@(launchedFromShortcut) };
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"doesthismatter"
initialProperties:initialProperties // Add the initial properties here
launchOptions:launchOptions];
...
}
在 RNN 的 V2 中,不再使用 rootView,而是直接调用:
[ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions];
因此我们无法将initialProperties 传递给rootView。
2。在代码的其他部分访问rootView
继续设置react-native-siri-shortcut:
// This method checks for shortcuts issued to the app
- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> *restorableObjects))restorationHandler
{
UIViewController *viewController = [self.window rootViewController];
RCTRootView *rootView = (RCTRootView*) [viewController view];
// If the initial properties say the app launched from a shortcut (see above), tell the library about it.
if ([[rootView.appProperties objectForKey:@"launchedFromShortcut"] boolValue]) {
ShortcutsModule.initialUserActivity = userActivity;
rootView.appProperties = @{ @"launchedFromShortcut":@NO };
}
[ShortcutsModule onShortcutReceivedWithUserActivity:userActivity];
return YES;
}
由于RCTRootView 没有被用来注册我们的应用程序,这部分代码可以工作吗?
我已经在 repo 中搜索了与 initialProps 和 reactView 相关的问题,并且我确实发现了一些问题,但从未得到答复并由于不活动而被关闭。
任何帮助将不胜感激。
【问题讨论】: