React Native中也會(huì)遇到判斷項(xiàng)目是Release還是Debug,針對(duì)不同的模式,我們可以做一些特意的配置,如服務(wù)器地址等。
首先我們看下在原生應(yīng)用中是怎么判斷的。
在Android中:
//在Android Studio項(xiàng)目中
if(BuildConfig.DEBUG){
//debug模式
}else{
//release模式
}
在iOS中:
#ifdef DEBUG
// debug模式
#else
//release 模式
#endif
在React Native中:
if(__DEV__){
// debug模式
}else{
// release模式
}
注:在項(xiàng)目打包時(shí)需要注意配置是否為release