提交 a8bb0384 authored 作者: JarvanMo's avatar JarvanMo

config log in pubspec.yaml

上级 d1c3dc0a
......@@ -19,7 +19,9 @@
package com.jarvan.fluwx.handlers
import android.content.Context
import android.content.pm.PackageManager
import android.util.Log
import com.jarvan.fluwx.BuildConfig
import com.tencent.mm.opensdk.constants.Build
import com.tencent.mm.opensdk.openapi.IWXAPI
import com.tencent.mm.opensdk.openapi.WXAPIFactory
......@@ -54,6 +56,16 @@ object WXAPiHandler : ILog {
fun registerApp(call: MethodCall, result: MethodChannel.Result, context: Context?) {
context?.let {
with(it) {
val appInfo =
packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
val enableLogging = appInfo.metaData.getString("WeChatDebugLogging", "")
if (enableLogging == "enabled" && BuildConfig.DEBUG) {
startLog()
}
}
}
if (call.argument<Boolean?>("android") == false) {
return
}
......@@ -89,12 +101,15 @@ object WXAPiHandler : ILog {
wxApi == null -> {
result.error("Unassigned WxApi", "please config wxapi first", null)
}
wxApi?.isWXAppInstalled != true -> {
result.error("WeChat Not Installed", "Please install the WeChat first", null)
}
(wxApi?.wxAppSupportAPI ?: 0) < Build.OPEN_BUSINESS_VIEW_SDK_INT -> {
result.error("WeChat Not Supported", "Please upgrade the WeChat version", null)
}
else -> {
result.success(true)
}
......@@ -102,19 +117,26 @@ object WXAPiHandler : ILog {
}
private fun registerWxAPIInternal(appId: String, context: Context) {
with(context) {
val appInfo =
packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
val enableLogging = appInfo.metaData.getString("WeChatDebugLogging", "")
if (enableLogging == "enabled" && BuildConfig.DEBUG) {
startLog()
}
}
val api = WXAPIFactory.createWXAPI(context.applicationContext, appId)
registered = api.registerApp(appId)
wxApi = api
}
fun startLog(call: MethodCall, result: MethodChannel.Result) {
fun startLog() {
wxApi?.setLogImpl(this)
result.success(true)
}
fun stopLog(call: MethodCall, result: MethodChannel.Result) {
fun stopLog() {
wxApi?.setLogImpl(null)
result.success(true)
}
override fun d(p0: String?, p1: String?) {
......
......@@ -32,14 +32,3 @@ enum WXMiniProgramType {
/// [WeChatScene.timeline]朋友圈
/// [WeChatScene.favorite]收藏
enum WeChatScene { session, timeline, favorite }
/// 打印日常的日志
/// 打印详细的日志
enum WXLogLevel {
normal(1),
unspecific(0);
final int level;
const WXLogLevel(this.level);
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论