react-native - 假设 AppDelegate 中不存在某些代码,react-native-navigation 安装说明的问题
问题描述
我正在尝试安装 react-native-navigation 并按照https://wix.github.io/react-native-navigation/#/docs/Installing在编辑 ios 文件部分的说明进行操作。说明告诉我编辑 AppDelegate.m。说明告诉我添加此代码,最终结果应如下所示。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... }
最终结果应该是这样的
#import "AppDelegate.h"
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <ReactNativeNavigation/ReactNativeNavigation.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
[ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions];
return YES;
}
@end
但我的 AppDelegate.m 看起来不像这样?相反,它看起来像这样......
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [RCTLinkingManager application:application openURL:url
sourceApplication:sourceApplication annotation:annotation];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"planzu"
initialProperties:nil];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
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
我应该如何进行?我应该消除顶部和底部方法吗?或者只是替换事件调用'didFinishLaunchingWithOptions'?
解决方案
您应该将您AppDelegate
的didFinishLaunchingWithOptions
方法修改为 RNN 文档中提到的方法。这是 RNN 的入口点,它取代了创建桥和根视图的通常的 react-native 设置。
您可以保留其他两种方法 (openURL
和sourceURLForBridge
) 不变。
推荐阅读
- c# - LINQ - 分组,然后有条件地求和
- javascript - VTK.js VR 不在 Room 中显示/显示手控制器
- java - java.sql.SQLIntegrityConstraintViolationException:列'library_idlibrary'不能为空
- c# - 当 `throw new` 旁边发生异常时,还有其他方法可以查看程序的行为吗?
- windows - 在 VPS 中使用 KeyboardEvent
- android - 如何使用用户定义的文档 ID 创建 Firebase Firestore 文档?
- css - 如何将 box-shadow 逗号分隔值与 filter: drop-shadow 一起使用?
- powerbi - 微软 Power BI | TOP 5 客户的销售额和销售额占总销售额的百分比(不仅仅是前 5 名)
- azure - azure_managed_disk 和 storage_data_disk 之间的关系
- spring - 我想在使用条件的搜索中排除多个条目