//
|
// AppDelegate.swift
|
// OKProject
|
//
|
// Created by alvin_y on 2020/5/20.
|
// Copyright © 2020 yangwang. All rights reserved.
|
//
|
|
import UIKit
|
import IQKeyboardManager
|
import MBProgressHUD
|
import Alamofire
|
import MetricKit
|
import RxRelay
|
import RxSwift
|
import RxCocoa
|
|
@UIApplicationMain
|
class AppDelegate: UIResponder, UIApplicationDelegate {
|
|
var window: UIWindow?
|
var backgroundTask:UIBackgroundTaskIdentifier?
|
|
// 登录信息
|
var loginInfo: LoginModel = readLogin()
|
|
// 用户信息
|
var userInfo: UserInfoModel = readUser()
|
|
/// 猎鹰
|
var trackManager: AMapTrackManager!
|
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
// Override point for customization after application launch.
|
setupIQManager()
|
setupAMap()
|
setupUM()
|
setupPaymentManager()
|
//获取token
|
if !(PDKeyChain.keyChainLoad() != nil) {
|
PDKeyChain.keyChainSave(NSUUID().uuidString)
|
}
|
UIActivityIndicatorView.appearance(whenContainedInInstancesOf: [MBProgressHUD.self]).color = UIColor.white //菊花 全局设置
|
window?.frame = UIScreen.main.bounds
|
window?.backgroundColor = .white
|
window?.rootViewController = YYNavigationController(rootViewController: HomeVC())
|
window?.makeKeyAndVisible()
|
checkVersion()
|
|
if #available(iOS 15.0, *) {
|
UITableView.appearance().sectionHeaderTopPadding = 0
|
}
|
return true
|
}
|
|
/// 配置IQManager
|
func setupIQManager() {
|
IQKeyboardManager.shared().isEnabled = true
|
IQKeyboardManager.shared().isEnableAutoToolbar = true
|
IQKeyboardManager.shared().shouldResignOnTouchOutside = true
|
IQKeyboardManager.shared().toolbarDoneBarButtonItemText = "完成"
|
}
|
|
/// 配置高德
|
func setupAMap() {
|
AMapServices.shared()?.apiKey = AMapApiKey
|
/**
|
// 猎鹰模块代码
|
let option = AMapTrackManagerOptions()
|
option.serviceID = ""
|
trackManager = AMapTrackManager.init(options: option)
|
trackManager.delegate = self
|
trackManager.allowsBackgroundLocationUpdates = true
|
trackManager.pausesLocationUpdatesAutomatically = false
|
trackManager.setLocalCacheMaxSize(50)
|
*/
|
}
|
|
/// 配置友盟
|
func setupUM(){
|
// UMConfigure.initWithAppkey(UmSocialAppkey, channel: "App Store")
|
// UMSocialManager.default().setPlaform(UMSocialPlatformType.wechatSession, appKey: WechatAppID, appSecret: WechatAppSecret, redirectURL: "http://mobile.umeng.com/social")
|
// UMSocialManager.default().setPlaform(UMSocialPlatformType.QQ, appKey: QQAppID, appSecret: QQAppSecret, redirectURL: "http://mobile.umeng.com/social")
|
// UMSocialManager.default().setPlaform(UMSocialPlatformType.sms, appKey: SMS, appSecret: SMSSecret, redirectURL: "http://www.baidu.com")
|
// UMSocialManager.default()?.openLog(false)
|
// // 一键登录
|
// let info = VerifySDKInfoKey
|
// UMCommonHandler.setVerifySDKInfo(info) { (reslutDic) in
|
// print("一键登录---->>>>>\(reslutDic)")
|
// }
|
|
}
|
/// 版本更新
|
func checkVersion(){
|
//获取当前手机安装使用的版本号
|
let localVersion:Int = Int((Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String).replacingOccurrences(of: ".", with: ""))!
|
// App Store版本号
|
let url = URL(string: "http://itunes.apple.com/lookup?id=\(AppId)")
|
var request = URLRequest(url: url!)
|
request.httpMethod = "POST"
|
let configuration:URLSessionConfiguration = URLSessionConfiguration.default
|
let session:URLSession = URLSession(configuration: configuration)
|
let task:URLSessionDataTask = session.dataTask(with: request) { (data, response, error)->Void in
|
if error == nil{
|
do{
|
let responseData:NSDictionary = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.allowFragments) as! NSDictionary
|
if let resultCount = responseData["resultCount"] as? NSNumber {
|
if resultCount.intValue > 0 {
|
if let arr = responseData["results"] as? NSArray {
|
if let dict = arr.firstObject as? NSDictionary {
|
if let version = dict["version"] as? String {
|
let version = Int(version.replacingOccurrences(of: ".", with: ""))!
|
loggerswift.log(s: "App Store版本号:\(version)")
|
loggerswift.log(s: "本地版本号:\(localVersion)")
|
if version > localVersion {
|
DispatchQueue.main.async{
|
alert(popup: .single, title: "提示", text: "您有新版本!", submitTitle: "去更新", cancelTitle: "") {
|
let updateUrl:URL = URL.init(string: "https://itunes.apple.com/cn/app/%E8%8E%B1%E4%BB%98mpos/id"+AppId+"?mt=8")!
|
if #available(iOS 10.0, *) {
|
UIApplication.shared.open(updateUrl, options: [:], completionHandler: nil)
|
} else {
|
UIApplication.shared.openURL(updateUrl)
|
}
|
} cancelClick: {
|
}
|
}
|
|
}
|
}
|
}
|
}
|
}
|
}
|
}catch{
|
print("catch")
|
}
|
}else{
|
print("error:\(error.debugDescription)")
|
}
|
}
|
task.resume()
|
}
|
func applicationDidBecomeActive(_ application: UIApplication) {
|
NotificationCenter.default.post(Notification.init(name: Notification.Name.init(YYRefreshInfo)))
|
}
|
|
func applicationDidEnterBackground(_ application: UIApplication) {
|
NotificationCenter.default.post(Notification.init(name: Notification.Name.init(YYRefreshInfo)))
|
}
|
|
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
|
return YYPaymentManager.shared.handleApplication(application, open: url, sourceApplication: sourceApplication, annotation: annotation) || UMSocialManager.default().handleOpen(url)
|
}
|
func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
|
return YYPaymentManager.shared.handleApplication(application, handleOpen: url) || UMSocialManager.default().handleOpen(url)
|
}
|
// NOTE: 9.0以后使用新API接口
|
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
|
|
return YYPaymentManager.shared.handleApplication(app, open: url, options: options) || UMSocialManager.default().handleOpen(url)
|
}
|
|
private func setupPaymentManager() {
|
|
YYPaymentManager.shared.configuredAlipay(appScheme: "jiYiXAlipay")
|
YYPaymentManager.shared.configuredWeChat(appID: WechatAppID)
|
}
|
}
|
|
// MARK: - AMapTrackManagerDelegate
|
extension AppDelegate: AMapTrackManagerDelegate
|
{
|
|
}
|
|
|
//
|
@available(iOS 13.0, *)
|
class AppMetrics: NSObject, MXMetricManagerSubscriber {
|
func receiveReports() {
|
let shared = MXMetricManager.shared
|
shared.add(self)
|
}
|
|
func pauseReports() {
|
let shared = MXMetricManager.shared
|
shared.remove(self)
|
}
|
|
// Receive daily metrics.
|
func didReceive(_ payloads: [MXMetricPayload]) {
|
// Process metrics.
|
}
|
|
// Receive diagnostics immediately when available.
|
@available(iOS 14.0, *)
|
func didReceive(_ payloads: [MXDiagnosticPayload]) {
|
// Process diagnostics.
|
}
|
}
|