objective-c - 如果有两个条件,如何结合jsbundle和代码推送?
问题描述
我在 XCode 上的 React Native 项目中设置了代码推送。
#ifdef DEBUG
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
jsCodeLocation = [CodePush bundleURL];
#endif
现在我想生成 jsbundle 并在 IOS 设备上构建项目。
但我发现这jsCodeLocation
是重复的。
#ifdef DEBUG
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
#else
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
我很困惑如何结合 jsCodeLocation ?
我不熟悉Objective-c。
解决方案
它在示例中提供:
#import "AppDelegate.h"
#import "RCTRootView.h"
#import "CodePush.h"
#import "RCTLog.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
RCTSetLogThreshold(RCTLogLevelInfo);
NSURL *jsCodeLocation;
jsCodeLocation = [CodePush bundleURL];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"CODE_PUSH_TEST_APP_NAME"
initialProperties:nil
launchOptions:launchOptions];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [[UIViewController alloc] init];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
}
@end
推荐阅读
- pygame - pygame 中的表面是否包含超过它可以显示的内容(在 20x20 表面上加载 40x40 图片)?
- python - Python readline 将我的打印定位在下面而不是旁边
- google-chrome - 如何使警报窗口也播放声音
- c# - 列表中的动态泛型类
- android-fragments - 如何在没有活动的片段中保存状态开始破坏Android Studio
- javascript - 在使用全局唯一标识符/srcdoc 创建的 iframe 上强制执行哪个 CSP?
- javascript - 删除 html 元素中的重复内容中的字符串
- visual-studio-code - VS Code 调优:在面板中合并资源管理器、搜索和源代码控制
- flutter - 尝试从 Stream Provider 检索和显示数据时出错
- python - Flask:如何自动化 OpenAPI v3 文档?