|
@@ -10,10 +10,8 @@ import Kingfisher
|
|
|
import UIKit
|
|
|
import UserNotifications
|
|
|
import WechatOpenSDK
|
|
|
+import Bugly
|
|
|
|
|
|
-// #if DEBUG
|
|
|
-// import DoraemonKit
|
|
|
-// #endif
|
|
|
|
|
|
// MARK: - 第三方相关工具类
|
|
|
|
|
@@ -22,32 +20,41 @@ class PQThirdPlatformUtil: NSObject {
|
|
|
static let shared = PQThirdPlatformUtil()
|
|
|
// 注册第三方
|
|
|
func register() {
|
|
|
-// // 注册微信
|
|
|
-// PQSingletoWXApiUtil.shared.registerApp()
|
|
|
-// // 注册bugly
|
|
|
-// let buglyConfig = BuglyConfig()
|
|
|
-// buglyConfig.reportLogLevel = .warn
|
|
|
-// #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 = 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: cBuglyAppkey, config: buglyConfig)
|
|
|
-// // 注册友盟
|
|
|
-// PQUMApiUtil.register()
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override private init() {
|
|
|
+ super.init()
|
|
|
+ }
|
|
|
+
|
|
|
+ override func copy() -> Any {
|
|
|
+ return self
|
|
|
+ }
|
|
|
+
|
|
|
+ override func mutableCopy() -> Any {
|
|
|
+ return self
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - bugly相关工具类
|
|
|
+class PQSingleBuglyUtil: NSObject {
|
|
|
+ static let shared = PQSingleBuglyUtil()
|
|
|
+ // 注册
|
|
|
+ func register(appID:String) {
|
|
|
+
|
|
|
+ // 注册bugly
|
|
|
+ let buglyConfig = BuglyConfig()
|
|
|
+ buglyConfig.reportLogLevel = .warn
|
|
|
+ buglyConfig.version = versionName + "-\(PQENVUtil.shared.envMode)"
|
|
|
+ PQLog(message: "Bugly版本号:\(BuglyConfig.version())")
|
|
|
+ buglyConfig.channel = 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)
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
override private init() {
|
|
@@ -66,28 +73,40 @@ class PQThirdPlatformUtil: NSObject {
|
|
|
// MARK: - 微信相关工具类
|
|
|
|
|
|
/// 微信相关工具类
|
|
|
+
|
|
|
+//初始化微信要使用的参数 e.g.
|
|
|
+/*
|
|
|
+ let state: String = "com.piaoquan.pqspeed"
|
|
|
+ let appid: String = "wxfc2fc07ab379e4bf"
|
|
|
+ let secret: String = "06f696424accb17b7234dce32e4821b4"
|
|
|
+ let universalLink: String = "https://speed.piaoquantv.com/"
|
|
|
+ let scope = "snsapi_userinfo"
|
|
|
+ */
|
|
|
+class WXApiInfo:NSObject {
|
|
|
+ let state: String = ""
|
|
|
+ let appid: String = ""
|
|
|
+ let secret: String = ""
|
|
|
+ let universalLink: String = ""
|
|
|
+ let scope = ""
|
|
|
+}
|
|
|
class PQSingletoWXApiUtil: NSObject {
|
|
|
static let shared = PQSingletoWXApiUtil()
|
|
|
var openId: String? // openID
|
|
|
// 回调
|
|
|
var wxApiUtilHander: ((_ userData: [String: Any]?, _ errorMsg: String?) -> Void)?
|
|
|
- let state: String = "com.piaoquan.pqspeed"
|
|
|
- let appid: String = "wxfc2fc07ab379e4bf"
|
|
|
- let secret: String = "06f696424accb17b7234dce32e4821b4"
|
|
|
- let universalLink: String = "https://speed.piaoquantv.com/"
|
|
|
- let scope = "snsapi_userinfo"
|
|
|
-
|
|
|
- func registerApp() {
|
|
|
+ var mAppInfo:WXApiInfo = WXApiInfo.init()
|
|
|
+ func registerApp(appInfo:WXApiInfo) {
|
|
|
+ mAppInfo = appInfo
|
|
|
#if DEBUG
|
|
|
WXApi.startLog(by: .detail) { msg in
|
|
|
PQLog(message: "微信回调Log--\(msg)")
|
|
|
}
|
|
|
#endif
|
|
|
- WXApi.registerApp(appid, universalLink: universalLink)
|
|
|
+ WXApi.registerApp(mAppInfo.appid, universalLink: mAppInfo.universalLink)
|
|
|
#if DEBUG
|
|
|
-// WXApi.checkUniversalLinkReady { step, result in
|
|
|
-// PQLog(message: "微信回调自检--\(step),result = \(result)")
|
|
|
-// }
|
|
|
+ WXApi.checkUniversalLinkReady { step, result in
|
|
|
+ PQLog(message: "微信回调自检--\(step),result = \(result)")
|
|
|
+ }
|
|
|
#endif
|
|
|
}
|
|
|
|
|
@@ -107,8 +126,8 @@ class PQSingletoWXApiUtil: NSObject {
|
|
|
return .shared
|
|
|
}
|
|
|
let req = SendAuthReq()
|
|
|
- req.scope = scope
|
|
|
- req.state = state
|
|
|
+ req.scope = mAppInfo.scope
|
|
|
+ req.state = mAppInfo.state
|
|
|
WXApi.send(req) { [weak self] isSuccess in
|
|
|
if !isSuccess {
|
|
|
self?.wxApiUtilHander!(nil, "您还未安装微信客户端!")
|
|
@@ -271,7 +290,7 @@ extension PQSingletoWXApiUtil: WXApiDelegate {
|
|
|
PQLog(message: "微信回调返回 -- \(resp)")
|
|
|
|
|
|
if resp.isKind(of: SendAuthResp.self) {
|
|
|
- if (resp as! SendAuthResp).state == state {
|
|
|
+ if (resp as! SendAuthResp).state == mAppInfo.state {
|
|
|
// accessToken(code: (resp as! SendAuthResp).code!)
|
|
|
} else {
|
|
|
if wxApiUtilHander != nil {
|
|
@@ -286,7 +305,7 @@ extension PQSingletoWXApiUtil: WXApiDelegate {
|
|
|
}
|
|
|
|
|
|
func accessToken(code: String) {
|
|
|
- let url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=\(appid)&secret=\(secret)&code=\(code)&grant_type=authorization_code"
|
|
|
+ let url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=\(mAppInfo.appid)&secret=\(mAppInfo.secret)&code=\(code)&grant_type=authorization_code"
|
|
|
DispatchQueue.global(qos: .userInitiated).async { [weak self] in
|
|
|
|
|
|
let zoneStr = try? String(contentsOf: URL(string: url)!, encoding: .utf8)
|
|
@@ -323,56 +342,6 @@ extension PQSingletoWXApiUtil: WXApiDelegate {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-// 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()
|
|
|
-// }
|
|
|
- }
|
|
|
-}
|
|
|
|
|
|
|