然后執行pod install 或者pod update
3.接下來就是使用了-初始化控件
#ifdef DEBUG
NSURL *jsCodeLocation = [NSURL
URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios"];
這里是你在調試模式下的時候使用。使用之前先要在react-native目錄下執行nam start (意思是啟動react native serive)
#else
NSURL * jsCodeLocation = [CodePush bundleURL];
這是使用codePush提供的bundleURL。前提是你本地已經有了js包。
當然要利用codePush進行代碼push,首先要先利用終端,進行code-push命令注冊添加應用,它會返回給你兩個key,一個是開發時候使用的key(Staging),一個是發布時候用的key(Production)。這個key需要注冊到項目的info里面:添加CodePushDeploymentKey字段,后面的value是string類型,填寫key。
注意的是:需要先在react native目錄下,終端執行:react-native bundle --entry-file index.ios.js --platform ios --dev false --bundle-output ./ios_output/main.jsbundle --assets-dest ./ios_output,然后把這個ios_output下的文件,引用到我們的原生項目里。因為我們的項目是使用本地的js包。當codePush服務器上有新的js包的時候,會去拉取到本地再使用。(當然,我們需要在index.ios.js里面寫上codePush.sync()同步的方法,不然我們怎么去觸發拉取最新的js包)
#endif
RCTRootView *rootView =
[[RCTRootViewalloc] initWithBundleURL : jsCodeLocation
moduleName :@"LotsOfGreetings"
// 這個LotsOfGreetings可以理解為約定好的模塊類型,在react-native目錄下的index.ios.js里面,需要注冊這個模塊
initialProperties :nil
launchOptions :nil];