方法和前面写过的在原生环境下集成差不多IOS原生环境下集成RN。这里着重讲一下可能会遇到的问题和解决方法。
因为CocoaPods和cordova/ionic的兼容不是很好,在这些混合环境下集成rn页面会导致podfile等文件路径找不错问题。
问题1:
报错:
1.Diff:/Podfile.lock:NO such file or directy
2.Diff:/Manifest.lock: NO such file or directy
3.The scanBox is not in syn with the Podfile.lock.Run 'pod install' or update your CocoaPods instrallation.
解决办法
网上有很多其他解决方法,比如说删掉 Build Phases下的Check Pods Manifest.lock。这些都治标不治本,虽然说编译能通过,会导致后面应用RCTRootView时,出现各种RN库之间的链接错误。所以,经过百般查找和尝试,得出下面解决方案。
修改原生工程下面的 “build-debug.xcconfig” 和 “build-release.xcconfig” 两个文件
1.build-debug.xconfig文件
#include "build.xcconfig"
GCC_PREPROCESSOR_DEFINITIONS = DEBUG=1
#include "build-extras.xcconfig"
// (CB-11792)
// @COCOAPODS_SILENCE_WARNINGS@ //
//#include "../pods-debug.xcconfig" //这里是pod帮我们添加的错误路径,这就是根本原因。修改成类似下面的路径即可。注意一些Pods文件夹和xcconfig文件的相对路径就行。
#include "../Pods/Target Support Files/Pods-PlatformHand/Pods-PlatformHand.debug.xcconfig"
2.build-release.xconfig文件
#include "build.xcconfig"
CODE_SIGN_IDENTITY = iPhone Distribution
CODE_SIGN_IDENTITY[sdk=iphoneos*] = iPhone Distribution
#include "build-extras.xcconfig"
// (CB-11792)
// @COCOAPODS_SILENCE_WARNINGS@ //
//#include "../pods-release.xcconfig" //这里是pod帮我们添加的错误路径,这就是根本原因。修改成类似下面的路径即可。注意一些Pods文件夹和xcconfig文件的相对路径就行
#include "../Pods/Target Support Files/Pods-PlatformHand/Pods-PlatformHand.release.xcconfig"
然后再重新执行一次pod命令,重新编译即可
pod install