Wallpaper_Home/wallpaper_project/AppDelegate.swift
2024-08-19 14:40:12 +08:00

223 lines
7.6 KiB
Swift
Raw Permalink 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
// wallpaper_project
import UIKit
import IQKeyboardManagerSwift
import AppLovinSDK
import FirebaseCore
import FirebaseAnalytics
import Alamofire
import FBSDKCoreKit
import MTGSDK
import AnyThinkSDK
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var overlayWindow: UIWindow?
var logTextView: UITextView?
var wasInBackground = false
static var shared: AppDelegate {
return UIApplication.shared.delegate as! AppDelegate
}
var isFirstLaunchq: Bool = true
var window: UIWindow?
var interstitialAd: MAInterstitialAd!
var retryAttempt = 0.0
var adCheckTimer: Timer?
var adCheckStartTime: Date?
let hasLaunchedBeforeKey = "hasLaunchedBefore"
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
IQKeyboardManager.shared.enable = true
let splashViewController = WA_limitsVCViewController()
//
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = splashViewController
self.window?.makeKeyAndVisible()
setdispatch()
initializationTopOn.toponeSDK()
let userDefaults = UserDefaults.standard
if userDefaults.bool(forKey: hasLaunchedBeforeKey){
let tt = UserDefaults.standard
print("-------\(tt.bool(forKey: "iswindows"))")
}else{
//
UserDefaults.standard.set(true, forKey: hasLaunchedBeforeKey)
UserDefaults.standard.set(false, forKey: "iswindows")
}
Analytics.logEvent("goin_app", parameters: nil)
//
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 applicationDidEnterBackground(_ application: UIApplication) {
}
func applicationWillEnterForeground(_ application: UIApplication) {
}
func applicationDidBecomeActive(_ application: UIApplication) {
}
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.")
}
}
func showOverlayWindow() {
//
let overlaySize = CGSize(width: 200, height: 300)
let overlayOrigin = CGPoint(x: UIScreen.main.bounds.width - overlaySize.width,
y: (UIScreen.main.bounds.height - overlaySize.height) - 200)
overlayWindow = UIWindow(frame: CGRect(origin: overlayOrigin, size: overlaySize))
//
overlayWindow?.windowLevel = UIWindow.Level.statusBar + 1
overlayWindow!.isUserInteractionEnabled = true
//
let overlayView = UIView(frame: overlayWindow!.bounds)
overlayView.isUserInteractionEnabled = true
overlayView.backgroundColor = UIColor.red.withAlphaComponent(0.5) //
overlayWindow?.addSubview(overlayView)
// let btn = UIButton(frame: overlayWindow!.bounds)
// btn.addTarget(self, action: #selector(showOverlayView), for: .touchUpInside)
// TextView
logTextView = UITextView(frame: overlayView.bounds.insetBy(dx: 10, dy: 10))
logTextView?.backgroundColor = UIColor.clear
logTextView?.textColor = UIColor.white
logTextView?.isEditable = false
logTextView?.isScrollEnabled = true
overlayView.addSubview(logTextView!)
// overlayView.addSubview(btn)
//
// overlayWindow?.rootViewController = UIViewController()
overlayWindow?.isHidden = false
}
func removeOverlayWindow() {
overlayWindow?.isHidden = true //
overlayWindow = nil //
}
func addLogMessage(_ message: String) {
if logTextView != nil {
let currentText = logTextView?.text ?? ""
let updatedText = "\(message)\n\n\(currentText)"
logTextView?.text = updatedText
//
let range = NSMakeRange(0, 0)
logTextView?.scrollRangeToVisible(range)
} else {
print("Log TextView is not initialized.")
}
}
}