diff --git a/README.md b/README.md index 2859372..946cd5e 100644 --- a/README.md +++ b/README.md @@ -1,53 +1,105 @@ # react-native-baidu-mtj -## Getting started +百度统计移动端 React Native 版本无埋点 SDK,解决了官方 RN 模块版本过低的问题,并加入了 ts 支持 -`$ npm install react-native-baidu-mtj --save` +# 使用方法 -### Mostly automatic installation +## 安装 -`$ react-native link react-native-baidu-mtj` +`$ yarn add react-native-baidu-mtj` -### Manual installation +低版本 React Native 需要手动建立连接 +`$ react-native link react-native-baidu-mtj` -#### iOS +## Android 端部署 -1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]` -2. Go to `node_modules` ➜ `react-native-baidu-mtj` and add `RNBaiduMtj.xcodeproj` -3. In XCode, in the project navigator, select your project. Add `libRNBaiduMtj.a` to your project's `Build Phases` ➜ `Link Binary With Libraries` -4. Run your project (`Cmd+R`)< +配置AndroidManifest.xml: -#### Android +1)添加权限声明 -1. Open up `android/app/src/main/java/[...]/MainActivity.java` - - Add `import com.reactlibrary.RNBaiduMtjPackage;` to the imports at the top of the file - - Add `new RNBaiduMtjPackage()` to the list returned by the `getPackages()` method -2. Append the following lines to `android/settings.gradle`: - ``` - include ':react-native-baidu-mtj' - project(':react-native-baidu-mtj').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-baidu-mtj/android') - ``` -3. Insert the following lines inside the dependencies block in `android/app/build.gradle`: - ``` - compile project(':react-native-baidu-mtj') - ``` +```xml + + + + + + + + + + + +``` -#### Windows -[Read it! :D](https://github.com/ReactWindows/react-native) +2)添加业务配置 + +```xml + + + + + + + + + + + + + + + + + + + + +``` -1. In Visual Studio add the `RNBaiduMtj.sln` in `node_modules/react-native-baidu-mtj/windows/RNBaiduMtj.sln` folder to their solution, reference from their app. -2. Open up your `MainPage.cs` app - - Add `using Baidu.Mtj.RNBaiduMtj;` to the usings at the top of the file - - Add `new RNBaiduMtjPackage()` to the `List` returned by the `Packages` method +3)App 中调用 +```js +import RNBaiduMtj from "react-native-baidu-mtj" +// ... ... +RNBaiduMtj.start() +``` + +## IOS 端部署 -## Usage -```javascript -import RNBaiduMtj from 'react-native-baidu-mtj'; +1)手动安装 pod 依赖 -// TODO: What to do with the module? -RNBaiduMtj; +```shell +cd yourReactNativeProject/ios/ +pod install ``` - \ No newline at end of file + +2)到主Target下,切到Build Settings,找到Linking部分的Other Linker Flags条目,双击后加入-ObjC配置。 + +![](https://i.loli.net/2021/07/02/xnCb4Bl85hTrXfU.png) + +3)编辑info.plist配置文件:打开主工程下Supporting Files文件夹下的info.plist文件,按照如下示例,新增mtj_appkey、mtj_deubglog两行参数,并写入您的appkey + +![](https://i.loli.net/2021/07/02/zmBFHO7iqkMnC4g.png) + +# API + +参考官方文档: + +- https://mtj.baidu.com/static/userguide/book/android/bconfig/api.html +- https://mtj.baidu.com/static/userguide/book/ios/bconfig/api.html \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index 2fae82a..b575470 100644 --- a/index.d.ts +++ b/index.d.ts @@ -11,7 +11,7 @@ declare var BaiduMobStat: { * @description 设置channelid * https://mtj.baidu.com/static/userguide/book/android/adconfig/channel/channel.html * @param appChannel 渠道值,数值自定义,不同渠道自己能区分即可,例如"baidu market" - * @param saveChannelWithCode 设置为true,保存设置 + * @param saveChannelWithCode 设置为true,保存设置(IOS 端无效) */ setAppChannel: (appChannel: string, saveChannelWithCode: boolean) => void; diff --git a/ios/RNBaiduMtj.podspec b/ios/RNBaiduMtj.podspec index aa3cc6c..906f9df 100644 --- a/ios/RNBaiduMtj.podspec +++ b/ios/RNBaiduMtj.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "RNBaiduMtj" - s.version = "2.0.5" + s.version = "2.0.6" s.summary = "RNBaiduMtj" s.description = <<-DESC RNBaiduMtj diff --git a/package.json b/package.json index 1fa95f1..0afa167 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-baidu-mtj", - "version": "2.0.5", + "version": "2.0.6", "description": "", "main": "index.js", "scripts": {