4

I migrated to React Native 0.60 from 0.59 and haven't managed to make iOS build work. I'm using React Native Navigation v3, Code Push and Sentry plugins. How does my AppDelegate.m should look?

Here is my attempt, but it's not working and I get "No bundle is present" when deploying to simulator:

#import "AppDelegate.h"

#import <CodePush/CodePush.h>

#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#if __has_include(<React/RNSentry.h>)
#import <React/RNSentry.h> // This is used for versions of react >= 0.40
#else
#import "RNSentry.h" // This is used for versions of react < 0.40
#endif
#import <ReactNativeNavigation/ReactNativeNavigation.h>
#import <React/RCTLinkingManager.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  return [RCTLinkingManager application:application openURL:url options:options];
}

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity
 restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
{
  return [RCTLinkingManager application:application
                   continueUserActivity:userActivity
                     restorationHandler:restorationHandler];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  NSURL *jsCodeLocation;

  #ifdef DEBUG
    jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
  #else
    jsCodeLocation = [CodePush bundleURL];
  #endif

  [ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions];

  return YES;
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

@end

terreb
  • 1,417
  • 2
  • 23
  • 40
  • 1
    https://react-native-community.github.io/upgrade-helper/ is a handy tool for verifying how your AppDelegate.m should look. Also have a look here for your bundler issue. https://github.com/facebook/react-native/issues/12754 – ap.dev Aug 20 '19 at 13:57
  • I'm aware of the upgrade helper. The problem is that all the packages I mentioned require custom bootstrapping and thus the tool is not really helpful as it shows the difference between 2 clean projects. – terreb Aug 21 '19 at 10:31
  • Btw, the upgrade helper doesn't event mention AppDelegate.m (I'm migrating from 0.59.8 to 0.60.4). I assume it has not changed and the way I have it now should work but it's doesn't... – terreb Aug 21 '19 at 12:24
  • I upgraded from v0.50 to v0.60 and it was a royal pain. IIRC I had to do several things in that 12754 issue link above to get my iOS build to run. I specifically remember having to manually bundle my js file (the comment from LuckyCrab commented on Apr 16, 2018 in that issue link). Also you shouldn't have to import those packages in your AppDelegate.m since RN handles the linking in v0.60+. You may need to manually unlink and (re)link your packages with react-native link/unlink commands. – ap.dev Aug 21 '19 at 12:44
  • Are you using react native navigation or code push? – terreb Aug 21 '19 at 12:48
  • I'm using react navigation v1.5.2. I'm not using code push. – ap.dev Aug 21 '19 at 13:03
  • Ok, then thank you for trying to help but you don't know what you're talking about. react navigation is different from react native navigation. The latter does require some tweaking on the native side even with latest RN version. As well as code push and I believe also sentry. – terreb Aug 21 '19 at 13:14
  • I have the same issue. Is it resolved? @terreb – Trọng Nguyễn Công Aug 26 '19 at 04:22
  • @TrọngNguyễnCông, if you're using the same packages/versions and have the same error due to wrong AppDelegate.m then see my answer below. If you have the same error "No bundle is present" and don't use those packages it might be due to something else and my answer won't be of any use for you. – terreb Aug 26 '19 at 13:14

1 Answers1

3

I managed to make my app work. Here is the updated AppDelegate.m:

#import "AppDelegate.h"

#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>

#import <ReactNativeNavigation/ReactNativeNavigation.h>
#import <CodePush/CodePush.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];

  [ReactNativeNavigation bootstrap:[self sourceURLForBridge: bridge] launchOptions:launchOptions];

  return YES;
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  return [CodePush bundleURL];
#endif
}

@end

For the new Sentry package (@sentry/react-native) no changes to AppDelegate.m are required (at least for the version I'm currently using 1.0.0-beta.7). The configuration includes running the wizard yarn sentry-wizard -i reactNative -p ios android and installing pods cd ios && pod install.

Please note all the above works for me and might not work for you if you have different setup or you have other packages requiring adjustments to AppDelegate.m. Tested with:

react: 16.8.6
react-native: 0.60.4
react-native-navigation: 3.1.0
react-native-code-push: 5.6.0
@sentry/react-native: 1.0.0-beta.7
terreb
  • 1,417
  • 2
  • 23
  • 40