a react native component for leancloud javascript-sdk
this component simply move the appId
and appKey
from the javascript file to native code as it's really easy to get those values from the js.bundle
in released app.
you have to install leancloud javascript-sdk first
npm install nihgwu/react-native-leancloud --save
react-native link react-native-leancloud
You need rnpm
(npm install -g rnpm
)
rnpm link react-native-leancloud
In XCode, in the project navigator:
- Right click Libraries
- Add Files to [your project's name]
- Go to
node_modules/react-native-leancloud/ios
- Add the
.xcodeproj
file
In XCode, in the project navigator, select your project.
- Add the
libRNLeanCloud.a
from the deviceinfo project to your project's Build Phases ➜ Link Binary With Libraries - Click
.xcodeproj
file you added before in the project navigator and go the Build Settings tab. Make sure All is toggled on (instead of Basic). - Look for Header Search Paths and make sure it contains both
$(SRCROOT)/../react-native/React
and$(SRCROOT)/../../React
- Mark both as recursive (should be OK by default).
Run your project (Cmd+R)
- in
MainApplication.java
:
+ import com.liteneo.RNLeanCloud.RNLeanCloudPackage;
public class MainApplication extends Application implements ReactApplication {
//......
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
+ new RNLeanCloudPackage("your leancloud appId", "your leancloud appKey"),
new MainReactPackage()
);
}
......
}
- in
MainActivity.java
:
+ import com.liteneo.RNLeanCloud.RNLeanCloudPackage;
public class MainActivity extends ReactActivity {
......
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
+ new RNLeanCloudPackage("your leancloud appId", "your leancloud appKey"),
new MainReactPackage()
);
}
}
- in
info.plist
+ <key>LeanCloudAppId</key>
+ <string>your leancloud appId</string>
+ <key>LeanCloudAppKey</key>
+ <string>your leancloud appKey</string>
import AV from 'leancloud-storage';
import RNLeanCloud from 'react-native-leancloud';
AV.init({
appId: RNLeanCloud.appId,
appKey: RNLeanCloud.appKey,
});