ReactNative配置环境的坑

按照文档配置了环境,却发现'React/RCTBundleURLProvider.h' file not found,这不是你的问题,网上那些解决方法可能不合适,这个时候你打开pachage.json,把最新的版本号更改为小一点的稳定版比如0.44.3

在APPdelegate.m中存在两种加载方式

APP框架套用js 的方式

NSURL*jsCodeLocation;

//  jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/as.index.bundle?platform=ios&dev=true"];

jsCodeLocation = [[RCTBundleURLProvidersharedSettings]jsBundleURLForBundleRoot:@"as.index"fallbackResource:nil];

// NavTabTest

//原生内嵌套js采用

RCTRootView*rootView = [[RCTRootViewalloc]initWithBundleURL:jsCodeLocation

moduleName:@"CoolProB"

initialProperties:nil

launchOptions:launchOptions];

rootView.backgroundColor= [[UIColoralloc]initWithRed:1.0fgreen:1.0fblue:1.0falpha:1];

//

self.window= [[UIWindowalloc]initWithFrame:[UIScreenmainScreen].bounds];

UIViewController*rootViewController = [UIViewControllernew];

rootViewController.view= rootView;

self.window.rootViewController= rootViewController;

[self.windowmakeKeyAndVisible];

直接 React 框架的方式,(注:React框架的 navigation 不是iOS原生的,所以跟navigationiOS是有差距的,官方是这么说,但我用Xcode 3D旋转查看 APP 层次时候发现是原生😆😆 TMD!)

NSURL*jsCodeLocation;

//  jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/as.index.bundle?platform=ios&dev=true"];

jsCodeLocation = [[RCTBundleURLProvidersharedSettings]jsBundleURLForBundleRoot:@"as.index"fallbackResource:nil];

// NavTabTest

// react框架采用

self.window= [[UIWindowalloc]initWithFrame:[UIScreenmainScreen].bounds];

self.window.backgroundColor= [UIColorwhiteColor];

[[RCCManagersharedInstance]initBridgeWithBundleURL:jsCodeLocationlaunchOptions:launchOptions];

此时模拟器运行可能会爆红,说8081端口怎么怎么滴,或者桌面运行js文件路径不对等,亲爱的,那可能也不是你的问题,只要你使用真机调试,如果真机跑通了,那你再回头跑一下模拟器,相信这下模拟器又神奇的好了!😆😆😆

再启动npmstart的时候 不要打开VPN,因为VPN可能会把你的端口路径放到美国 日本等你VPN挂载的地方


尽量查看官方demo,毕竟,网上那些写法可能跟你版本都不一样
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容