AppDelegate.swift
10.3 KB
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
//
// AppDelegate.swift
// metaCode
//
// Created by iOS on 2023/5/30.
//
import UIKit
import CNLiveRequestBastKit
import IQKeyboardManagerSwift
import CNLiveShareToolKit
//import RangersAPM
import CNLiveEnvironment
import CNLivePayCostModule
import JFHeroBrowser
import ZFPlayer
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
// var orientationLock = UIInterfaceOrientationMask.allButUpsideDown // 默认支持方向
// func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
// return self.orientationLock
// }
func application(_ appUITableViewRowDatalication: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
JFHeroBrowserGlobalConfig.default.networkImageProvider = HeroNetworkImageProvider.shared
// Override point for customization after application launch.
//tencentAppId wxAppId
// WXApi.startLog(by: .detail) { log in
// print("1111:\(log)")
// }
CNLiveShareManager.registeredShareView(whenDidFinishLaunch: universalLinkURL, appId: APPId, tencentAppId: tencentAppId, wxAppId: wxAppId, wxSecret: wxSecret, weiBoAppId: "")
// WXApi.checkUniversalLinkReady { step, result in
// print("111:\(step),\(result.success),\(result.errorInfo),\(result.suggestion)")
// }
CNLiveShareImageManager().wxAppid = wxAppId
CNLiveShareImageManager().wxSecret = wxSecret
CNLiveNetworking.networkStatus { status in
if(status == .notReachable){
NotificationCenter.default.post(name: Notification.Name.NetworkStatus.CNLiveNetworkStatusNotificationNotReachable, object: nil)
}
if(status == .unknown){
NotificationCenter.default.post(name: Notification.Name.NetworkStatus.CNLiveNetworkStatusNotificationUnknown, object: nil)
}
if status == .reachableViaWWAN {
NotificationCenter.default.post(name: Notification.Name.NetworkStatus.CNLiveNetworkStatusNotificationReachableViaWWAN, object: nil)
}
if status == .reachableViaWiFi {
NotificationCenter.default.post(name: Notification.Name.NetworkStatus.CNLiveNetworkStatusNotificationReachableViaWiFi, object: nil)
}
}
//设置APP环境
CNLiveMCEnvironmentManager.shared.setupEnvironment(environment: .production)
CNLiveEnvironmentManager.setMetaCodeEnvironment(.productionAppStore)
CNLivePaySDK.sharedCNLivePayManager().registerApp(CNLiveMCEnvironmentManager.shared.appId_wjj, appKey: CNLiveMCEnvironmentManager.shared.appKey_wjj, isTestEnvironment: false)
CNLivePaySDK.sharedCNLivePayManager().registerWXApi(withWXAppId: wxAppId, universalLink: universalLinkURL)
window = UIWindow.init(frame: UIScreen.main.bounds)
window?.backgroundColor = KVCBackgroupColor
let is_login = UserDefaults.standard.bool(forKey: "is_login")
window?.rootViewController = is_login ? CNLiveBaseTabBarViewController.init() : UINavigationController(rootViewController: CNLiveLoginViewController.init())
window?.makeKeyAndVisible()
if is_login{
//获取用户信息 /api/identityApi/getUserMsg
CNLiveMineViewModel.requestGetUserMsg(sid: UserInfoManager.shared.userInfo.uid) { result, respStatue in
if respStatue == .success{
if let res = result as? MineGetUserMsgUsersModel{
let userInfo = UserInfoManager.shared.userInfo
userInfo.userMsgUsers = res
userInfo.currentUser = res.verifyUsers.first
UserInfoManager.cacheUserInfo(userInfo: userInfo)
if var userDic = UserDefaults.standard.dictionary(forKey: UserInfoManager.shared.userInfo.uid){
}else{
let tempDic = NSMutableDictionary()
UserDefaults.standard.setValue(tempDic, forKey: UserInfoManager.shared.userInfo.uid)
UserDefaults.standard.synchronize()
}
}
}
}
}
///设置APM监控SDK
// let apmConfig = RangersAPMConfig.init(appID: "591048", appToken: "8dcc7f8b0a3a4aee8ef698311ef89a62")
// apmConfig.channel = "App Store"
// apmConfig.deviceIDSource = .fromAPMService
// apmConfig.defaultMonitors = .apmCrashMonitorSwitch
// RangersAPM.setUserID(is_login ? UserInfoManager.shared.userInfo.uid : "userID")
// RangersAPM.allowDebugLog { log in
// print("APMPlus : %@",log)
// }
// RangersAPM.start(with: apmConfig)
AppDelegate_configRequestManager()
AppDelegate_configIQKeyboardManager()
CNLivePayCostModule.finishLaunchingWithPayPluginSettings(withWWXAppId: wxAppId, hostURL: universalLinkURL)
// //认证-下滑原生页数据库
// let databasePath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
// let filePath = "\(databasePath)/CNLiveDownSlideModelDataBase.db"
// let databaseManager = DatabaseManager(filePath: filePath)
// databaseManager.createTable()
//
// if databaseManager.hasDataInTable(){
// databaseManager.updateIsGetPage(isGetPage: 1)
// }else{
// print("noData")
// }
return true
}
func application(_ application: UIApplication, didFailToContinueUserActivityWithType userActivityType: String, error: Error) {
}
/// 在这里写支持的旋转方向,为了防止横屏方向,应用启动时候界面变为横屏模式
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if window is ZFLandscapeWindow {
var orientationMask: ZFInterfaceOrientationMask = .portrait
if #available(iOS 16.0, *) {
orientationMask = ZFLandscapeRotationManager_iOS16.supportedInterfaceOrientations(for: window)
} else if #available(iOS 15.0, *) {
orientationMask = ZFLandscapeRotationManager_iOS15.supportedInterfaceOrientations(for: window)
} else {
orientationMask = ZFLandscapeRotationManager.supportedInterfaceOrientations(for: window)
}
if orientationMask != ZFInterfaceOrientationMask(rawValue: 0) {
return UIInterfaceOrientationMask(rawValue: orientationMask.rawValue)
}
}
// if allowOrentitaionRotation {
// return .allButUpsideDown
// }
return .portrait
}
// MARK: - 键盘处理
func AppDelegate_configIQKeyboardManager() {
IQKeyboardManager.shared.enable = true
IQKeyboardManager.shared.enableAutoToolbar = true //工具条
IQKeyboardManager.shared.shouldResignOnTouchOutside = true //点击背景收回键盘
IQKeyboardManager.shared.toolbarDoneBarButtonItemText = "完成"
// IQKeyboardManager.shared.preventShowingBottomBlankSpace = true
// IQKeyboardManager.shared.preventShowingBottomBlankSpace = false
IQKeyboardManager.shared.toolbarTintColor = .lightGray
IQKeyboardManager.shared.keyboardDistanceFromTextField = 5.0
}
// MARK: - 网络请求通用参数
func AppDelegate_configRequestManager() {
let kAppBundleID = Bundle.main.bundleIdentifier ?? ""
let uuid : String = UIDevice.current.identifierForVendor?.uuidString.replacingOccurrences(of: "-", with: "") ?? ""
let ver : String = Bundle.main.infoDictionary?["CFBundleVersion"] as! String
let p : Dictionary = ["platform_id":kAppBundleID,"uuid":uuid,"plat":"i","ver":ver,"appId":APPId,"timestamp":String(NSNumber(floatLiteral: Date().timeIntervalSince1970).intValue),"clientPlat":"i","frmId":"ios"]
CNLiveNetworking.setupDefaultParam(p)
let shop_dic : Dictionary = ["Phone-Model":"iPhone","Uid":UserInfoManager.shared.userInfo.uid ,"CFBundleShortVersionString":ver,"Shop-Version":"0.6.2"]
CNLiveNetworking.setupDSShopParam(shop_dic)
CNLiveNetworking.setRequestTimeoutInterval(60)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.setupSignKey(APPKey)
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setResponseSerializerType(.JSON)
CNLiveNetworking.setupBaseURL(APPLoginHost)
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
CNLiveShareManager.handleOpenUniversalLink(userActivity)
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
CNLiveShareManager.handleOpen(url)
return true
}
}
//@available(iOS 13.0, *)
//extension UIWindowScene {
// func setInterfaceOrientation(_ orientation: UIInterfaceOrientation) {
// let orientationMask: UIInterfaceOrientationMask
// switch orientation {
// case .portrait:
// orientationMask = .portrait
// case .landscapeLeft:
// orientationMask = .landscapeLeft
// case .landscapeRight:
// orientationMask = .landscapeRight
// default:
// orientationMask = .allButUpsideDown
// }
//
// if #available(iOS 16.0, *) {
// let geometryPreferences = UIWindowScene.GeometryPreferences.iOS(interfaceOrientations: orientationMask)
// self.requestGeometryUpdate(geometryPreferences) { error in
// print("Error requesting geometry update: \(error.localizedDescription)")
// }
// } else {
// UIDevice.current.setValue(orientation.rawValue, forKey: "orientation")
// UINavigationController.attemptRotationToDeviceOrientation()
// }
// }
//}