【问题标题】:React Native 0.60+ on iOS: Code Push, Sentry, React Native Navigation v3 and AppDelegate.miOS 上的 React Native 0.60+:代码推送、Sentry、React Native Navigation v3 和 AppDelegate.m
【发布时间】:2019-08-20 11:30:37
【问题描述】:

我从 0.59 迁移到 React Native 0.60 并没有设法使 iOS 构建工作。我正在使用 React Native Navigation v3、Code Push 和 Sentry 插件。我的 AppDelegate.m 应该是什么样子?

这是我的尝试,但它不起作用,并且在部署到模拟器时出现“没有捆绑包”:

#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

【问题讨论】:

  • react-native-community.github.io/upgrade-helper 是一个方便的工具,用于验证 AppDelegate.m 的外观。还可以在这里查看您的捆绑程序问题。 github.com/facebook/react-native/issues/12754
  • 我知道升级助手。问题是我提到的所有包都需要自定义引导,因此该工具并没有真正的帮助,因为它显示了 2 个干净项目之间的区别。
  • 顺便说一句,升级助手没有提到 AppDelegate.m(我正在从 0.59.8 迁移到 0.60.4)。我认为它没有改变,我现在拥有它的方式应该可以工作,但它没有......
  • 我从 v0.50 升级到了 v0.60,这真是一种痛苦。 IIRC 我必须在上面的 12754 问题链接中做几件事才能让我的 iOS 版本运行。我特别记得必须手动捆绑我的 js 文件(来自 LuckyCrab 的评论于 2018 年 4 月 16 日在该问题链接中评论)。此外,您不必在 AppDelegate.m 中导入这些包,因为 RN 在 v0.60+ 中处理链接。您可能需要使用 react-native 链接/取消链接命令手动取消链接和(重新)链接您的包。
  • 你是用 react 原生导航还是代码推送?

标签: react-native wix-react-native-navigation react-native-code-push react-native-sentry


【解决方案1】:

我设法让我的应用正常运行。这是更新后的 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

对于新的 Sentry 包 (@sentry/react-native),不需要对 AppDelegate.m 进行任何更改(至少对于我当前使用的版本 1.0.0-beta.7)。配置包括运行向导 yarn sentry-wizard -i reactNative -p ios android 和安装 pod cd ios &amp;&amp; pod install

请注意,如果您有不同的设置或者您有其他需要调整 AppDelegate.m 的软件包,上述所有内容都对我有用,并且可能对您不起作用。测试:

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

【讨论】:

  • 谢谢,我已经解决了这个问题。但是我需要在更新后重新启动我的应用程序 2 次以避免应用程序崩溃
猜你喜欢
  • 2017-10-11
  • 2018-10-29
  • 1970-01-01
  • 2022-10-25
  • 1970-01-01
  • 2019-06-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多