过程基本可以参考React Native中文网:https://reactnative.cn/docs/0.50/integration-with-existing-apps.html#content
坑1:项目目录下的存放ios和android项目的文件夹不要命名成/ios或/andorid,直接是ios或android就可以了;
坑2:podfile中的ios版本,必须大于或等于9.0,否则不能正常安装。报啥错忘记了。。。;
坑3 :出现The name of the given podspec `GLog` doesn't match the expected one `GLog` 时,请将GLog都改成glog;
坑4:或者也不叫坑只是中文网上介绍的太繁琐,要简单,修改AppDelegate.m代码(注意module名称要和项目上的对应上),可以直接用下面代码:
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* 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/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"IosDemo"
initialProperties:nil
launchOptions:launchOptions];
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;
}
@end
坑5:当你以为都配置完,可以快乐的跑起来时,出现了错误:
folly/folly-config.h' file not found
。不要去搞什么清除RN缓存,本人亲测,没卵用。是react native版本出现 的一个问题。解决办法是修改
![抓狂](https://static-blog.csdn.net/xheditor/xheditor_emot/default/crazy.gif)
node_modules/React-native/React.podspec文件,增加React/Fabric/*。
s.subspec "Core" do |ss|
ss.dependency "yoga", "#{package["version"]}.React"
ss.source_files = "React/**/*.{c,h,m,mm,S,cpp}"
ss.exclude_files = "**/__tests__/*",
"IntegrationTests/*",
"React/DevSupport/*",
"React/Inspector/*",
"ReactCommon/yoga/*",
"React/Fabric/*",
"React/Cxx*/*",
我在IOS原生项目集成RN时基本就遇到这几个大坑,解决后,顺利跑起来了
![得意](https://static-blog.csdn.net/xheditor/xheditor_emot/default/proud.gif)