代码之家  ›  专栏  ›  技术社区  ›  Michael Kessler

将React Native导航与iOS中的React Native Callkit集成

  •  1
  • Michael Kessler  · 技术社区  · 6 年前

    我正在尝试将RNN(react native navigation)与RNCK(react native callkit)集成到iOS中。
    问题是,它们中的每一个都需要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中,这个设置被简化了,我看不出一个合适的方法来将两个框架集成到一个项目中,除了分叉RNN并添加一个单独的初始化器,它将接收 moduleProvider

    1 回复  |  直到 6 年前
        1
  •  2
  •   Artal    6 年前

    RNN还有一个 bootstrap 采用委托对象参数(实现 RNNBridgeManagerDelegate )这允许您注入额外的模块。

    下面是一个示例,说明如何在应用程序委托本身设置为委托的情况下引导RNN:

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

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

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