Skip to content

Commit

Permalink
feat: 更新 Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
EsunR committed Jul 2, 2021
1 parent bd0a164 commit 48760f2
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 38 deletions.
122 changes: 87 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.GET_TASKS" />
```

#### Windows
[Read it! :D](https://github.com/ReactWindows/react-native)
2)添加业务配置

```xml
<!-- 您从百度网站获取的APP KEY,根据实际您的APP申请的APP_KEY进行修改 -->
<meta-data
android:name="BaiduMobAd_STAT_ID"
android:value="a9e2ad84a2" />

<!-- 渠道商编号 -->
<meta-data
android:name="BaiduMobAd_CHANNEL"
android:value="Baidu Market" />

<!-- 是否开启错误日志统计,默认为false -->
<meta-data
android:name="BaiduMobAd_EXCEPTION_LOG"
android:value="true" />

<!-- 日志仅在wifi网络下发送,默认为false -->
<meta-data
android:name="BaiduMobAd_ONLY_WIFI"
android:value="false" />

<!-- 是否获取基站位置信息 ,默认为true -->
<meta-data
android:name="BaiduMobAd_CELL_LOCATION"
android:value="true" />

<!-- 是否获取GPS位置信息,默认为true -->
<meta-data
android:name="BaiduMobAd_GPS_LOCATION"
android:value="true" />

<!-- 是否获取WIFI位置信息,默认为true -->
<meta-data
android:name="BaiduMobAd_WIFI_LOCATION"
android:value="true" />
```

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<IReactPackage>` 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
```


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
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion ios/RNBaiduMtj.podspec
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-baidu-mtj",
"version": "2.0.5",
"version": "2.0.6",
"description": "",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 48760f2

Please sign in to comment.