|
@@ -6,21 +6,25 @@
|
|
|
// Copyright © 2020 BytesFlow. All rights reserved.
|
|
|
//
|
|
|
|
|
|
+import Bugly
|
|
|
import Kingfisher
|
|
|
import UIKit
|
|
|
import UserNotifications
|
|
|
import WechatOpenSDK
|
|
|
-import Bugly
|
|
|
-
|
|
|
|
|
|
// MARK: - 第三方相关工具类
|
|
|
|
|
|
/// 第三方相关工具类
|
|
|
-class PQThirdPlatformUtil: NSObject {
|
|
|
+public class PQThirdPlatformUtil: NSObject {
|
|
|
static let shared = PQThirdPlatformUtil()
|
|
|
// 注册第三方
|
|
|
func register() {
|
|
|
-
|
|
|
+ // 注册微信
|
|
|
+ PQSingletoWXApiUtil.shared.registerApp()
|
|
|
+ // 注册bugly
|
|
|
+ PQSingleBuglyUtil.shared.register()
|
|
|
+ // 注册友盟
|
|
|
+ PQUMApiUtil.register()
|
|
|
}
|
|
|
|
|
|
override private init() {
|
|
@@ -37,35 +41,43 @@ class PQThirdPlatformUtil: NSObject {
|
|
|
}
|
|
|
|
|
|
// MARK: - bugly相关工具类
|
|
|
+
|
|
|
public class PQSingleBuglyUtil: NSObject {
|
|
|
static let shared = PQSingleBuglyUtil()
|
|
|
// 注册
|
|
|
- func register(appID:String) {
|
|
|
-
|
|
|
+ func register() {
|
|
|
// 注册bugly
|
|
|
let buglyConfig = BuglyConfig()
|
|
|
buglyConfig.reportLogLevel = .warn
|
|
|
- buglyConfig.version = versionName + "-\(PQENVUtil.shared.envMode)"
|
|
|
- BFLog(message: "Bugly版本号:\(BuglyConfig.version())")
|
|
|
- buglyConfig.channel = channelID
|
|
|
- buglyConfig.deviceIdentifier = BFLoginUserInfo.shared.isLogin() ? BFLoginUserInfo.shared.uid : getMachineCode()
|
|
|
+ #if DEBUG
|
|
|
+ buglyConfig.version = versionName + ".6666"
|
|
|
+ PQLog(message: "Bugly版本号:\(BuglyConfig.version())")
|
|
|
+ #else
|
|
|
+ if PQENVUtil.shared.envMode == .ENVModeOnline {
|
|
|
+ buglyConfig.version = versionName + "." + versionCode
|
|
|
+ } else if PQENVUtil.shared.envMode == .ENVModePre {
|
|
|
+ buglyConfig.version = versionName + ".8888"
|
|
|
+ } else {
|
|
|
+ buglyConfig.version = versionName + ".9999"
|
|
|
+ }
|
|
|
+ #endif
|
|
|
+ buglyConfig.channel = PQBFConfig.shared.channelID
|
|
|
+ buglyConfig.deviceIdentifier = PQLoginUserInfo.shared.isLogin() ? PQLoginUserInfo.shared.uid : getMachineCode()
|
|
|
buglyConfig.unexpectedTerminatingDetectionEnable = true
|
|
|
buglyConfig.blockMonitorEnable = true
|
|
|
buglyConfig.blockMonitorTimeout = 2
|
|
|
- Bugly.start(withAppId: cBuglyAppkey, config: buglyConfig)
|
|
|
-
|
|
|
-
|
|
|
+ Bugly.start(withAppId: PQBFConfig.shared.buglyAppkey, config: buglyConfig)
|
|
|
}
|
|
|
|
|
|
override private init() {
|
|
|
super.init()
|
|
|
}
|
|
|
|
|
|
- public override func copy() -> Any {
|
|
|
+ override public func copy() -> Any {
|
|
|
return self
|
|
|
}
|
|
|
|
|
|
- public override func mutableCopy() -> Any {
|
|
|
+ override public func mutableCopy() -> Any {
|
|
|
return self
|
|
|
}
|
|
|
}
|
|
@@ -74,7 +86,7 @@ public class PQSingleBuglyUtil: NSObject {
|
|
|
|
|
|
/// 微信相关工具类
|
|
|
|
|
|
-//初始化微信要使用的参数 e.g.
|
|
|
+// 初始化微信要使用的参数 e.g.
|
|
|
/*
|
|
|
let state: String = "com.piaoquan.pqspeed"
|
|
|
let appid: String = "wxfc2fc07ab379e4bf"
|
|
@@ -82,20 +94,21 @@ public class PQSingleBuglyUtil: NSObject {
|
|
|
let universalLink: String = "https://speed.piaoquantv.com/"
|
|
|
let scope = "snsapi_userinfo"
|
|
|
*/
|
|
|
-public class WXApiInfo:NSObject {
|
|
|
+public class WXApiInfo: NSObject {
|
|
|
public var state: String = ""
|
|
|
public var appid: String = ""
|
|
|
public var secret: String = ""
|
|
|
public var universalLink: String = ""
|
|
|
public var scope = ""
|
|
|
}
|
|
|
+
|
|
|
public class PQSingletoWXApiUtil: NSObject {
|
|
|
- public static let shared = PQSingletoWXApiUtil()
|
|
|
+ public static let shared = PQSingletoWXApiUtil()
|
|
|
var openId: String? // openID
|
|
|
// 回调
|
|
|
public var wxApiUtilHander: ((_ userData: [String: Any]?, _ errorMsg: String?) -> Void)?
|
|
|
- var mAppInfo:WXApiInfo = WXApiInfo.init()
|
|
|
- public func registerApp(appInfo:WXApiInfo) {
|
|
|
+ var mAppInfo: WXApiInfo = WXApiInfo()
|
|
|
+ public func registerApp(appInfo: WXApiInfo) {
|
|
|
mAppInfo = appInfo
|
|
|
#if DEBUG
|
|
|
WXApi.startLog(by: .detail) { msg in
|
|
@@ -260,7 +273,7 @@ public class PQSingletoWXApiUtil: NSObject {
|
|
|
|
|
|
/// 是否安装了微信
|
|
|
/// - Returns: <#description#>
|
|
|
- public func isInstallWX() -> Bool {
|
|
|
+ public func isInstallWX() -> Bool {
|
|
|
return UIApplication.shared.canOpenURL(URL(string: "weixin://")!)
|
|
|
}
|
|
|
|
|
@@ -268,11 +281,11 @@ public class PQSingletoWXApiUtil: NSObject {
|
|
|
super.init()
|
|
|
}
|
|
|
|
|
|
- public override func copy() -> Any {
|
|
|
+ override public func copy() -> Any {
|
|
|
return self
|
|
|
}
|
|
|
|
|
|
- public override func mutableCopy() -> Any {
|
|
|
+ override public func mutableCopy() -> Any {
|
|
|
return self
|
|
|
}
|
|
|
}
|
|
@@ -343,5 +356,67 @@ extension PQSingletoWXApiUtil: WXApiDelegate {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// MARK: - 友盟相关工具类
|
|
|
+
|
|
|
+/// 友盟相关工具类
|
|
|
+class PQUMApiUtil: NSObject {
|
|
|
+ class func register() {
|
|
|
+ // 注册友盟
|
|
|
+ UMConfigure.setEncryptEnabled(true)
|
|
|
+ // 初始化友盟所有组件产品
|
|
|
+ UMConfigure.initWithAppkey(PQBFConfig.shared.umAppkey, channel: PQBFConfig.shared.channelID)
|
|
|
+ #if DEBUG
|
|
|
+ UMConfigure.setLogEnabled(true)
|
|
|
+ #endif
|
|
|
+ PQLog(message: "友盟版本号:\(UMConfigure.version())")
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
-
|
|
|
+// MARK: - 统计分析工具类
|
|
|
+
|
|
|
+/// 统计分析工具类
|
|
|
+class PQAnalyticsUtil: NSObject {
|
|
|
+ /// 页面时长统计
|
|
|
+ /// - Parameters:
|
|
|
+ /// - pageName: 页面名称
|
|
|
+ /// - isBegin: 开始/结束
|
|
|
+ /// - Returns: <#description#>
|
|
|
+ class func pageAutoTimeAnalytics(pageName: String?, isBegin: Bool) {
|
|
|
+ if pageName == nil || pageName?.count ?? 0 <= 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ PQLog(message: "页面时长统计:isBegin = \(isBegin),pageName = \(pageName ?? "")")
|
|
|
+ if isBegin {
|
|
|
+ MobClick.beginLogPageView(pageName)
|
|
|
+ } else {
|
|
|
+ MobClick.endLogPageView(pageName)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 事件统计
|
|
|
+ /// - Parameters:
|
|
|
+ /// - eventId: 事件ID
|
|
|
+ /// - attributes: 事件属性
|
|
|
+ /// - Returns: <#description#>
|
|
|
+ class func eventAnalytics(eventId: String?, attributes: [String: Any]?) {
|
|
|
+ if eventId == nil || eventId?.count ?? 0 <= 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ PQLog(message: "自定义事件统计:eventId = \(eventId ?? ""),attributes = \(attributes ?? [:])")
|
|
|
+ if attributes != nil && attributes?.count ?? 0 > 0 {
|
|
|
+ MobClick.event(eventId!, attributes: attributes!)
|
|
|
+ } else {
|
|
|
+ MobClick.event(eventId!)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 账号统计
|
|
|
+ /// - Returns: <#description#>
|
|
|
+ class func accountAnalytics() {
|
|
|
+ if PQLoginUserInfo.shared.accessToken.count > 0 {
|
|
|
+ MobClick.profileSignIn(withPUID: PQLoginUserInfo.shared.accessToken, provider: cPrimarykey)
|
|
|
+ } else {
|
|
|
+ MobClick.profileSignOff()
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|