Skip to content

Commit

Permalink
feat: 增加微信的日志开关
Browse files Browse the repository at this point in the history
  • Loading branch information
9527001 committed Apr 14, 2022
1 parent f04cc26 commit fe3edea
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
20 changes: 20 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@ class ShareSelectorPage extends StatelessWidget {
child: const Text('Get ExtMessage'),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: OutlinedButton(
onPressed: () async {
bool? success = await startLog(logLevel: WXLogLevel.NORMAL);
print('startLog:$success\n');
},
child: const Text('start log'),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: OutlinedButton(
onPressed: () async {
dynamic success = await stopLog();
print('stopLog:$success\n');
},
child: const Text('stop log'),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: OutlinedButton(
Expand Down
25 changes: 25 additions & 0 deletions ios/Classes/FluwxPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result

if ([@"registerApp" isEqualToString:call.method]) {
[self registerApp:call result:result];
} else if ([@"startLog" isEqualToString:call.method]) {
[self startLog:call result:result];
} else if ([@"stopLog" isEqualToString:call.method]) {
[self stopLog:call result:result];
} else if ([@"isWeChatInstalled" isEqualToString:call.method]) {
[self checkWeChatInstallation:call result:result];
} else if ([@"sendAuth" isEqualToString:call.method]) {
Expand Down Expand Up @@ -124,6 +128,27 @@ - (void)registerApp:(FlutterMethodCall *)call result:(FlutterResult)result {
result(@(isWeChatRegistered));
}

- (void)startLog:(FlutterMethodCall *)call result:(FlutterResult)result {
NSNumber *typeInt = call.arguments[@"logLevel"];
WXLogLevel logLevel = WXLogLevelDetail;
if ([typeInt isEqualToNumber:@1]) {
logLevel = WXLogLevelDetail;
} else if ([typeInt isEqualToNumber:@0]) {
logLevel = WXLogLevelNormal;
}
NSLog(@"%@",call.arguments);
[WXApi startLogByLevel:logLevel logBlock:^(NSString * _Nonnull log) {
NSLog(@"%@",log);
}];
result([NSNumber numberWithBool:true]);

}

- (void)stopLog:(FlutterMethodCall *)call result:(FlutterResult)result {
[WXApi stopLog];
result([NSNumber numberWithBool:true]);
}

- (void)checkWeChatInstallation:(FlutterMethodCall *)call result:(FlutterResult)result {
result(@([WXApi isWXAppInstalled]));
}
Expand Down
11 changes: 11 additions & 0 deletions lib/src/fluwx_iml.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ Future<String?> getExtMsg() {
return _channel.invokeMethod('getExtMsg');
}

/// start Log
/// defalult [WXLogLevel.DETAIL]
Future<bool?> startLog({WXLogLevel logLevel = WXLogLevel.DETAIL}) async {
return await _channel.invokeMethod('startLog', {'logLevel': logLevel.toNativeInt()});
}

/// stop log
Future<bool?> stopLog() async {
return await _channel.invokeMethod('stopLog');
}

/// Share your requests to WeChat.
/// This depends on the actual type of [model].
/// see [_shareModelMethodMapper] for detail.
Expand Down
17 changes: 17 additions & 0 deletions lib/src/wechat_enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,20 @@ extension MiniProgramTypeExtensions on WXMiniProgramType {
}
}
}

/// 打印日常的日志
/// 打印详细的日志
enum WXLogLevel { NORMAL, DETAIL }

extension LogLevelExtensions on WXLogLevel {
int toNativeInt() {
switch (this) {
case WXLogLevel.DETAIL:
return 1;
case WXLogLevel.NORMAL:
return 0;
default:
return 0;
}
}
}

0 comments on commit fe3edea

Please sign in to comment.