IOS原生项目集成React Native遇到的坑

过程基本可以参考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版本出现 的一个问题。解决办法是修改
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时基本就遇到这几个大坑,解决后,顺利跑起来了 得意
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值