164 lines
5.6 KiB
Swift
164 lines
5.6 KiB
Swift
//
|
|
// AppDelegate.swift
|
|
// AnXuanApp
|
|
//
|
|
// Created by SHEN on 2025/4/21.
|
|
//
|
|
import NetworkExtension
|
|
import CloudKit
|
|
import Async
|
|
import RealmSwift
|
|
import Realm
|
|
import HandyJSON
|
|
import Alamofire
|
|
import SwiftyStoreKit
|
|
import TPInAppReceipt
|
|
|
|
import Kingfisher
|
|
|
|
@main
|
|
class AppDelegate: UIResponder, UIApplicationDelegate,UNUserNotificationCenterDelegate,OpenInstallDelegate {
|
|
var window: UIWindow?
|
|
|
|
|
|
|
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
|
OpenInstallSDK.initWith(self)
|
|
netInit()
|
|
ANXUANMyVPNManager.sharedVpnJmManager.vpnJmsetup()
|
|
SwiftyStoreKit.completeTransactions(atomically: false) { purchasesArr in
|
|
for purchaseOne in purchasesArr {
|
|
switch purchaseOne.transaction.transactionState {
|
|
case .purchased, .restored :
|
|
if purchaseOne.needsFinishTransaction {
|
|
self.orderMySupplement(purchaseOne)
|
|
}
|
|
case .failed, .purchasing, .deferred:
|
|
break
|
|
}
|
|
}
|
|
}
|
|
let JmNoticeCenter = UNUserNotificationCenter.current()
|
|
JmNoticeCenter.delegate = self
|
|
JmNoticeCenter.requestAuthorization(options: [.alert, .badge, .sound]) { granted, _ in
|
|
if granted == true {
|
|
print("允许通知")
|
|
} else {
|
|
print("不允许通知")
|
|
}
|
|
}
|
|
application.registerForRemoteNotifications()
|
|
IQKeyboardManager.shared().isEnabled = true
|
|
let vc = ANXUANFirstVC()
|
|
window?.backgroundColor = .clear;
|
|
window?.rootViewController = UINavigationController(rootViewController: vc)
|
|
window?.makeKeyAndVisible()
|
|
UIApplication.shared.setMinimumBackgroundFetchInterval(1000)
|
|
return true
|
|
}
|
|
|
|
|
|
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
|
|
// 将用户的用户名和deviceToken发送给服务器,让服务器进行保存备份即可
|
|
print("deviceToken as NSData:\(deviceToken as NSData)")
|
|
let tokenJmString = deviceToken.map{String(format:"%02.2hhx",$0)}.joined()
|
|
|
|
UserDefaults.standard.setValue(tokenJmString, forKey: AXUserField.DeviceJmToken)
|
|
NSLog("tokenString = %@", tokenJmString);
|
|
|
|
}
|
|
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: any Error) {
|
|
print("deviceToken as error:\(error.localizedDescription)")
|
|
}
|
|
|
|
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
|
|
application.applicationIconBadgeNumber = 0
|
|
|
|
if application.applicationState == .active {
|
|
return // 前台情况下 不做操作
|
|
}
|
|
if application.applicationState == .inactive {
|
|
let par : Parameters = ["deviceToken":UserDefaults.standard.string(forKey: AXUserField.DeviceJmToken) ?? "","osType":"ios"]
|
|
AF.request(MyJmUtils.getJmCurrentUrl() + AXNXUANNewApi.JmphMgs, method: .post,parameters: par).responseString{ response in
|
|
switch response.result {
|
|
case .success(let value):
|
|
print("denglu:\(value)==")
|
|
|
|
case .failure(let error):
|
|
|
|
print("请求失败:\(error)")
|
|
|
|
}
|
|
}
|
|
}
|
|
// 进行页面的跳转
|
|
}
|
|
|
|
|
|
/**
|
|
* IQKeyboard
|
|
*/
|
|
// func IQKeyboardManagerInit() {
|
|
// let manager = IQKeyboardManager.shared
|
|
// manager.enable = true
|
|
// manager.shouldResignOnTouchOutside = true
|
|
// manager.enableAutoToolbar = false
|
|
// manager.disabledDistanceHandlingClasses.add(TGCourseDailyViewController.self)
|
|
// }
|
|
|
|
func applicationDidEnterBackground(_ application: UIApplication) {
|
|
var bgAXTaskID: UIBackgroundTaskIdentifier = .invalid
|
|
|
|
bgAXTaskID = UIApplication.shared.beginBackgroundTask(withName: "AXBackgroundTask") {
|
|
|
|
UIApplication.shared.endBackgroundTask(bgAXTaskID)
|
|
bgAXTaskID = .invalid
|
|
}
|
|
}
|
|
//苹果内购补单漏单
|
|
func reqSupplementProduct(_ getPurchase:Purchase){
|
|
SwiftyStoreKit.finishTransaction(getPurchase.transaction)
|
|
}
|
|
|
|
/**
|
|
* SVProgress
|
|
*/
|
|
// func SVProgressHUDInit() {
|
|
// SVProgressHUD.setDefaultStyle(.custom)
|
|
// SVProgressHUD.setForegroundColor(.white)
|
|
// SVProgressHUD.setBackgroundColor(UIColor.black.withAlphaComponent(0.8))
|
|
// SVProgressHUD.setDefaultMaskType(.clear)
|
|
// SVProgressHUD.setMaximumDismissTimeInterval(2.0)
|
|
// }
|
|
|
|
func netInit(){
|
|
_ = Session(
|
|
serverTrustManager: ServerTrustManager(
|
|
allHostsMustBeEvaluated: false,
|
|
evaluators: [
|
|
"*": DisabledTrustEvaluator()
|
|
]
|
|
)
|
|
)
|
|
}
|
|
|
|
func orderMySupplement(_ Myproduct:Purchase){
|
|
SwiftyStoreKit.fetchReceipt(forceRefresh: false) { getresult in
|
|
switch getresult {
|
|
case .success(let getOvderData):
|
|
_ = getOvderData.base64EncodedString(options: [])
|
|
do {
|
|
self.reqSupplementProduct(Myproduct)
|
|
} catch {
|
|
|
|
}
|
|
break
|
|
case .error(_):
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|