- 安装
推荐使用 yarn,npm各种暗坑
yarn add janalytics-react-native
yarn add jcore-react-native
集成完成遇到安卓获取不到统计信息,我在官方github提了一个issues,如果你也遇到了可以参考这个
- 集成
推荐手动,自动link各种坑
Android
your project/android/settings.gradle
include ':app', 'janalytics-react-native', 'jcore-react-native'
project(':janalytics-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/janalytics-react-native/android')
project(':jcore-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/jcore-react-native/android')
your project/android/app/build.gradle
android {
...
defaultConfig {
applicationId "your application id"
...
manifestPlaceholders = [
JPUSH_APPKEY: "your app key", //在此替换你的APPKey
JPUSH_CHANNEL: "developer-default", //应用渠道号, 默认即可
]
}
}
...
dependencies {
implementation project(':janalytics-react-native')
implementation project(':jcore-react-native')
}
your project/android/app/src…/MainApplication.java
// 需要 import JAnalyticsInterface 和 JAnalyticsPackage
import cn.jiguang.analytics.android.api.JAnalyticsInterface;
import cn.jpush.reactnativejanalytics.JAnalyticsPackage;
public class MainApplication extends Application implements ReactApplication {
// 是否关闭 Log,默认不关闭
private static boolean SHUTDOWN_LOG = false;
// 是否关闭 toast,默认不关闭
private static boolean SHUTDOWN_TOAST = false;
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new JAnalyticsPackage(SHUTDOWN_TOAST, SHUTDOWN_LOG)
);
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, false);
// 在 Init 之前调用,设置为 true,则会打印 debug 级别日志,否则只会打印 warning 级别以上的日志
// JAnalyticsInterface.setDebugMode(true);
JAnalyticsInterface.init(this);
}
}
IOS
project navigator 右键Libraries 选择 Add Files to “project name“,
node_modules/janalytics-react-native/ios/RCTJAnalyticsModule.xcodeproj
node_modules/janalytics-react-native/ios/RCTJCoreModule.xcodeproj
Build Phases>link Binary Aith Libraries
libRCTJAnalyticsModule.a
libRCTJCoreModule.a