宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-07-05 0d8f5fc8a516bfd07e425909e4a4432600572ee7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
//
//  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.
    }
}