2

I am trying to to integrate RNN (React Native Navigation) with RNCK (React Native CallKit) in iOS.
The problem is that each of them requires a unique setup in Xcode project's AppDelegate.

Both of them need jsCodeLocation:

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

RNN setup:

[ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions];

RNCK setup:

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];

I see this (outdated) issue in RNCK repo, which leads to this (also outdated) issue and both talk about RNN 1, while in RNN 2 this setup is simplified and I don't see a proper way to integrate both frameworks in one project except forking the RNN and adding a separate initialiser that will receive moduleProvider...

Michael Kessler
  • 14,245
  • 13
  • 50
  • 64

1 Answers1

3

RNN has an additional bootstrap method that takes a delegate object parameter (which implements RNNBridgeManagerDelegate) that allows you to inject extra modules.

Here's an example of how you can bootstrap RNN with the app delegate itself set as the delegate:

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

You can then implement the delegate method and return the RNCallKit object:

- (NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge {
  RNCallKit *rncallkit = [[RNCallKit alloc] init];
  return @[rncallkit];
}
Artal
  • 8,933
  • 2
  • 27
  • 30
  • I'm not an iOS developer, could you also please tell me where I should be putting the second snippet of code? I get the following warning under bridgeManagerDelegate:self `Sending 'AppDelegate *const __strong' to parameter of incompatible type 'id'` – glocore Jan 27 '19 at 14:30
  • 1
    @platonish `extraModulesForBridge` needs to be implemented in whatever interface that you set to be your delegate. In the example I set it to `self` which is the `AppDelegate` itself, so `extraModulesForBridge` needs to be in your `AppDelegate` in this case. Regarding the warning - you need to declare that the object conform to the delegate protocol, example for this specific case - `AppDelegate `. you can read more about it here: https://developer.apple.com/library/archive/documentation/General/Conceptual/DevPedia-CocoaCore/Protocol.html – Artal Jan 27 '19 at 16:09