【发布时间】: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