Skip to content

nihgwu/react-native-leancloud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-leancloud

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.

Install

you have to install leancloud javascript-sdk first

npm install nihgwu/react-native-leancloud --save

Automatically link

With React Native 0.27+

react-native link react-native-leancloud

With older versions of React Native

You need rnpm (npm install -g rnpm)

rnpm link react-native-leancloud

Manually link

iOS

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)

Android

With React Native 0.29+

  • 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()
      );
    }
    
    ......
  }

With older versions of React Native:

  • 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()
      );
    }
  }

Configuration

iOS

  • in info.plist
+   <key>LeanCloudAppId</key>
+   <string>your leancloud appId</string>
+   <key>LeanCloudAppKey</key>
+   <string>your leancloud appKey</string>

Android

see Manually link for Android

Usage

import AV from 'leancloud-storage';
import RNLeanCloud from 'react-native-leancloud';

AV.init({
  appId: RNLeanCloud.appId,
  appKey: RNLeanCloud.appKey,
});