Day_Count_Memory_Days/anniversary_Project/AppDelegate.swift
2024-08-08 13:50:34 +08:00

225 lines
7.3 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// AppDelegate.swift
// anniversary_Project
//
// Created by 16 on 2024/4/11.
//
import UIKit
import IQKeyboardManagerSwift
import Photos
import SVProgressHUD
import AppLovinSDK
import FirebaseCore
import FirebaseAnalytics
import Alamofire
import FBSDKCoreKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate,UNUserNotificationCenterDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// window = UIWindow()
// window?.frame = UIScreen.main.bounds
IQKeyboardManager.shared.enable = true
LuxADConfigure.shareInstance().checkATT()
LuxADConfigure.shareInstance().configureADByFirebase(with: self.window!)
ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
setdispatch()
stePermissions()
self.window?.makeKeyAndVisible()
//
if #available(iOS 13.0, *) {
window?.overrideUserInterfaceStyle = .light
}
return true
}
func application(_ app: UIApplication,open url: URL,options:[UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
ApplicationDelegate.shared.application(
app,
open: url,
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplication.OpenURLOptionsKey.annotation]
)
}
//
func applicationWillEnterForeground(_ application: UIApplication) {
}
//
func applicationDidBecomeActive(_ application: UIApplication) {
LuxADManager.shareInstance().showOpenAD()
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert, .sound, .badge])
}
func stePermissions(){
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
if granted {
print("Permission granted")
} else if let error = error {
print("Permission denied: \(error.localizedDescription)")
}
}
requestPhotoLibraryPermission()
setNetwork()
// 使
let healthManager = HealthManager()
//
healthManager.requestAuthorization { (success, error) in
if success {
print("HealthKit authorization granted")
} else if let error = error {
print("HealthKit authorization failed with error: \(error.localizedDescription)")
}
}
}
func requestPhotoLibraryPermission() {
//
let status = PHPhotoLibrary.authorizationStatus()
//
switch status {
case .authorized:
// 访
print("相册权限已授权")
case .denied, .restricted:
// 访
print("相册权限已拒绝或受限,请在设置中开启权限")
case .notDetermined:
//
PHPhotoLibrary.requestAuthorization { (newStatus) in
DispatchQueue.main.async {
if newStatus == .authorized {
// 访
print("用户已授权访问相册")
} else {
// 访
print("用户未授权访问相册")
}
}
}
case .limited:
print("用户已授权此应用程序访问有限的照片库")
@unknown default:
//
print("未知的相册权限状态")
}
}
func setNetwork(){
// URL
if let url = URL(string: "https://www.baidu.com/") {
// URLSession
let session = URLSession.shared
//
let task = session.dataTask(with: url) { (data, response, error) in
if let error = error {
print("网络请求出错:\(error)")
}
}
//
task.resume()
} else {
print("URL无效")
}
}
}
func setdispatch(){
// 使
let dispatchGroup = DispatchGroup()
// IDFA
dispatchGroup.enter()
DispatchQueue.global(qos: .background).async {
requestTrackingAuthorization { idfa in
DispatchQueue.main.async {
if let idfa = idfa {
print("IDFA: \(idfa)")
StartManager.shared.idfaid = idfa
print("Stored IDFA: \(StartManager.shared.idfaid ?? "N/A")")
} else {
print("IDFA is not available or tracking authorization denied.")
}
dispatchGroup.leave()
}
}
}
// IP
dispatchGroup.enter()
DispatchQueue.global(qos: .background).async {
if let localIP = getLocalIPAddress() {
DispatchQueue.main.async {
print("Local IP Address: \(localIP)")
StartManager.shared.localIP = localIP
dispatchGroup.leave()
}
} else {
DispatchQueue.main.async {
print("Local IP Address not available")
dispatchGroup.leave()
}
}
}
// IP
dispatchGroup.enter()
DispatchQueue.global(qos: .background).async {
getPublicIPAddress { publicIP in
DispatchQueue.main.async {
if let publicIP = publicIP {
print("Public IP Address: \(publicIP)")
StartManager.shared.publicIP = publicIP
print("Stored Public IP Address: \(StartManager.shared.publicIP ?? "N/A")")
} else {
print("Public IP Address not available")
}
dispatchGroup.leave()
}
}
}
// ID
dispatchGroup.enter()
DispatchQueue.global(qos: .background).async {
let deviceID = UIDevice.current.identifierForVendor?.uuidString
DispatchQueue.main.async {
StartManager.shared.devicID = deviceID
print("Device ID: \(StartManager.shared.devicID ?? "N/A")")
dispatchGroup.leave()
}
}
//
dispatchGroup.notify(queue: .main) {
print("All tasks are completed.")
}
}