OGeek|极客世界-中国程序员成长平台

标题: ios - 在 iOS 中将 react-native-navigation 与 react-native-callkit 集成 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:00
标题: ios - 在 iOS 中将 react-native-navigation 与 react-native-callkit 集成

我正在尝试在 iOS 中将 RNN(React Native Navigation)与 RNCK(React Native CallKit)集成。
问题是它们中的每一个都需要在 Xcode 项目的 AppDelegate 中进行独特的设置。

两者都需要jsCodeLocation:

NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot"index" fallbackResource:nil];

RNN 设置:

[ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions];

RNCK 设置:

RNCallKit *rncallkit = [[RNCallKit alloc] init];
RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:jsCodeLocation
                                          moduleProvider:^{ return @[rncallkit]; }
                                           launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                 moduleName"MyApp"
                                          initialProperties:nil];

我看到 this (outdated) issue in RNCK repo , 这导致 this (also outdated) issue并且都谈到了 RNN 1,而在 RNN 2 中,这个设置被简化了,除了 fork RNN 并添加一个单独的初始化器来接收 moduleProvider 之外,我没有看到将这两个框架集成到一个项目中的正确方法>...



Best Answer-推荐答案


RNN 有一个额外的 bootstrap 方法,它接受一个委托(delegate)对象参数(实现 RNNBridgeManagerDelegate),允许您注入(inject)额外的模块。

下面是一个示例,说明如何将应用委托(delegate)本身设置为委托(delegate)来引导 RNN:

- (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)launchOptions {
  NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot"index" fallbackResource:nil];
  [ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions bridgeManagerDelegate:self];
  return YES;
}

然后您可以实现委托(delegate)方法并返回 RNCallKit 对象:

- (NSArray<id<RCTBridgeModule>> *)extraModulesForBridgeRCTBridge *)bridge {
  RNCallKit *rncallkit = [[RNCallKit alloc] init];
  return @[rncallkit];
}

关于ios - 在 iOS 中将 react-native-navigation 与 react-native-callkit 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54309685/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4