-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
90 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters