Skip to content

Commit

Permalink
发布0.3.2,修复 #16
Browse files Browse the repository at this point in the history
  • Loading branch information
yz1311 committed Apr 9, 2021
1 parent e8acf98 commit 63a7563
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 31 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.3.2 (2021-04-09)
* 实现ios端的`postException`,修复[#16](https://github.com/yz1311/rn-bugly/issues/16)
* 添加`startCrashReport``closeCrashReport`
`getCurrentTag``getUserData``getBuglyVersion`等接口

# 0.3.1 (2021-03-17)
* 由于jcenter仓库的问题,暂时固定`com.tencent.bugly:nativecrashreport`版本为`3.8.0`

Expand Down
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $ pod install
...
//初始化bugly,会自动读取info.plist中的参数
[RNBugly startWithAppId];
return YES;
return YES;
}
```
`info.plist`文件读取SDK初始化参数,可配置的参数如下(`除Appid为必填外,其它可选`):
Expand Down Expand Up @@ -76,7 +76,7 @@ public void onCreate() {
//初始化并且自动检查更新
RNBuglyModule.init(getApplicationContext(),"注册时申请的APPID",false);
//仅仅初始化(推荐使用该方法,所有的检查更新触发都都js端,更加灵活)
//仅仅初始化(推荐使用该方法,所有的检查更新触发都在js端,更加灵活)
RNBuglyModule.initWithoutAutoCheckUpgrade(getApplicationContext(),"注册时申请的APPID",false);
}
```
Expand Down Expand Up @@ -109,9 +109,27 @@ RNBugly.checkUpgrade({
//获取更新信息
//注意:更新信息获取一次后会储存在本地,即使后台控制停止该版本更新,该方法依旧可以获取到数据
let updateInfo = await RNBugly.getUpgradeInfo();


//上报自定义异常信息
RNBugly.postException({
errorMsg: 'login error',
stack: 'sadasdasd\nzxzxsds',
extraInfo: {
userInfo: 'test',
password: '12345'
}
})
```

具体方法请查看: [index.d.ts](./index.d.ts)
bugly后端异常信息如下:

![](https://tva1.sinaimg.cn/large/008eGmZEgy1gpdin9v721j30ww04imxk.jpg)
<br/>
<br/>
![](https://tva1.sinaimg.cn/large/008eGmZEgy1gpdiomwgs7j30w6068aal.jpg)

其他方法及注释请查看: [index.d.ts](types/index.d.ts)

参考[demo](./example),或者下载[example.apk](https://zhaoyang.lanzous.com/ib832sh)体验

Expand Down
36 changes: 36 additions & 0 deletions android/src/main/java/com/reactlibrary/bugly/RNBuglyModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableMapKeySetIterator;
import com.facebook.react.bridge.ReadableType;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.tencent.bugly.Bugly;
import com.tencent.bugly.beta.Beta;
Expand All @@ -22,7 +23,10 @@
import com.tencent.bugly.crashreport.CrashReport;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class RNBuglyModule extends ReactContextBaseJavaModule {

Expand Down Expand Up @@ -172,6 +176,38 @@ public void setUserSceneTag(int tagId) {
CrashReport.setUserSceneTag(getReactApplicationContext(), tagId);
}

@ReactMethod
public void startCrashReport() {
CrashReport.startCrashReport();
}

@ReactMethod
public void closeCrashReport() {
CrashReport.closeCrashReport();
}

@ReactMethod
public void getCurrentTag(final Promise promise) {
promise.resolve(CrashReport.getUserSceneTagId(getReactApplicationContext()));
}

@ReactMethod
public void getUserData(final Promise promise) {
Set<String> keys = CrashReport.getAllUserDataKeys(getReactApplicationContext());
Iterator iterator = keys.iterator();
WritableMap map = Arguments.createMap();
while (iterator.hasNext()) {
String key = (String)iterator.next();
map.putString(key, CrashReport.getUserData(getReactApplicationContext(), key));
}
promise.resolve(map);
}

@ReactMethod
public void getBuglyVersion(final Promise promise) {
promise.resolve(CrashReport.getBuglyVersion(getReactApplicationContext()));
}

@ReactMethod
public void putUserData(String userKey, String userValue, Promise promise) {
try
Expand Down
49 changes: 38 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
/**
* 设置当前的用户id
* 精确定位到某个用户的异常
* @param userId
* @param userId
*/
setUserId: function (userId) {
if(Platform.OS === 'android') {
Expand All @@ -27,14 +27,14 @@ export default {
if(Platform.OS === 'android') {
RNBugly.setAppChannel(appChannel);
} else {

}
},
setAppPackage: function (appPackage) {
if(Platform.OS === 'android') {
RNBugly.setAppPackage(appPackage);
} else {

}
},
setTag: function (tagId) {
Expand All @@ -44,13 +44,32 @@ export default {
RNBugly.setTag(tagId);
}
},
startCrashReport: function () {
if(Platform.OS === 'android') {
RNBugly.startCrashReport();
} else {

}
},
closeCrashReport: function () {
RNBugly.closeCrashReport();
},
getCurrentTag: function () {
return RNBugly.getCurrentTag();
},
getUserData: function () {
return RNBugly.getUserData();
},
getBuglyVersion: function () {
return RNBugly.getBuglyVersion();
},
/**
* 自定义Map参数可以保存发生Crash时的一些自定义的环境信息。在发生Crash时会随着异常信息一起上报并在页面展示。
* 最多可以有9对自定义的key-value(超过则添加失败);
* key限长50字节,value限长200字节,过长截断;
* key必须匹配正则:[a-zA-Z[0-9]]+。
* @param {*} userKey
* @param {*} userValue
* @param {*} userKey
* @param {*} userValue
*/
putUserData: function (userKey,userValue) {
return RNBugly.putUserData(userKey,userValue);
Expand Down Expand Up @@ -87,19 +106,27 @@ export default {
/**
* Android Only,打印日志
* 用户传入TAG和日志内容。该日志将在Logcat输出,并在发生异常时上报。
* @param {*} level
* @param {*} tag
* @param {*} log
* @param {*} level
* @param {*} tag
* @param {*} log
*/
log: function (level, tag, log) {
if(Platform.OS === 'android') {
RNBugly.log(level,tag,log);
}
},
//Android Only,主动上传日志
//主动上传日志
postException: function (params) {
if(Platform.OS === 'android') {
RNBugly.postException(params);
if(!params.errorType) {
params.errorType = 'React Native Exception';
}
if(!params.category) {
if(Platform.OS === 'android') {
params.category = 8;
} else {
params.category = 5;
}
}
RNBugly.postException&&RNBugly.postException(params);
}
};
41 changes: 40 additions & 1 deletion ios/RNBugly.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#import "RNBugly.h"
#import <Bugly/Bugly.h>
#import <React/RCTConvert.h>

@implementation RNBugly

Expand Down Expand Up @@ -34,10 +35,48 @@ + (void)startWithAppId
[Bugly setTag:tag];
}

RCT_EXPORT_METHOD(closeCrashReport)
{
[Bugly closeCrashReport];
}

RCT_EXPORT_METHOD(getCurrentTag:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)
{
NSUInteger tag = [Bugly currentTag];
resolve([NSNumber numberWithUnsignedInteger:tag]);
}

RCT_EXPORT_METHOD(getUserData:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)
{
NSDictionary* dict = [Bugly allUserValues];
resolve(dict);
}

RCT_EXPORT_METHOD(getBuglyVersion:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)
{
resolve([Bugly sdkVersion]);
}

RCT_EXPORT_METHOD(putUserData:(NSString *)userKey:(NSString *)userValue)
{
[Bugly setUserValue:userValue forKey:userKey];
}

RCT_EXPORT_METHOD(postException:(NSDictionary *)params)
{
NSInteger category = [RCTConvert NSInteger:[params objectForKey:@"category"]];
NSString *errorType = [RCTConvert NSString:[params objectForKey:@"errorType"]];
NSString *errorMsg = [RCTConvert NSString:[params objectForKey:@"errorMsg"]];
NSString *stack = [RCTConvert NSString:[params objectForKey:@"stack"]];
NSArray *stackTraceArray = [stack componentsSeparatedByString:@""];
NSDictionary *extraInfo = [RCTConvert NSDictionary:[params objectForKey:@"extraInfo"]];
if(extraInfo == nil) {
extraInfo = [NSMutableDictionary dictionary];
}
[Bugly reportExceptionWithCategory:category name:errorMsg reason:@" " callStack:stackTraceArray extraInfo:extraInfo terminateApp:NO];
}
@end

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

{
"name": "rn-bugly",
"version": "0.3.1",
"version": "0.3.2",
"description": "bugly for react-native,支持统计,android支持全量升级",
"main": "index.js",
"types": "./types/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
Loading

0 comments on commit 63a7563

Please sign in to comment.