MoviaBox/MoviaBox/AppDelegate/SceneDelegate.swift
2025-05-09 16:31:18 +08:00

96 lines
3.3 KiB
Swift

//
// SceneDelegate.swift
// MoviaBox
//
// Created by on 2025/4/8.
//
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
private var timer: Timer?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
let tabBarController = SPTabBarController()
SPAPPTool.mainTabBarController = tabBarController
let hasOpenApp = UserDefaults.standard.object(forKey: kSPHasBeenOpenedAPPDefaultsKey) as? Bool
window = UIWindow(windowScene: windowScene)
if hasOpenApp == true {
SPAPPTool.isAppOpen = true
window?.rootViewController = tabBarController
} else {
SPAPPTool.isAppOpen = false
let vc = SPGuideViewController()
vc.openAppBlock = {
self.handleOpenApp()
}
window?.rootViewController = vc
}
window?.makeKeyAndVisible()
//线
timer = Timer.scheduledTimer(timeInterval: 60 * 10, target: self, selector: #selector(handleOnLine), userInfo: nil, repeats: true)
}
func sceneDidDisconnect(_ scene: UIScene) {
// Called as the scene is being released by the system.
// This occurs shortly after the scene enters the background, or when its session is discarded.
// Release any resources associated with this scene that can be re-created the next time the scene connects.
// The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead).
}
func sceneDidBecomeActive(_ scene: UIScene) {
// Called when the scene has moved from an inactive state to an active state.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
handleOpenAppMessage(webpageURL: nil)
SPStatAPI.requestEnterApp()
}
func sceneWillResignActive(_ scene: UIScene) {
// Called when the scene will move from an active state to an inactive state.
// This may occur due to temporary interruptions (ex. an incoming phone call).
SPStatAPI.requestLeaveApp()
}
func sceneWillEnterForeground(_ scene: UIScene) {
// Called as the scene transitions from the background to the foreground.
// Use this method to undo the changes made on entering the background.
}
func sceneDidEnterBackground(_ scene: UIScene) {
// Called as the scene transitions from the foreground to the background.
// Use this method to save data, release shared resources, and store enough scene-specific state information
// to restore the scene back to its current state.
}
}
extension SceneDelegate {
///线
@objc private func handleOnLine() {
SPStatAPI.requestStatOnLine()
}
///app
@objc private func handleOpenApp() {
window?.rootViewController = SPAPPTool.mainTabBarController!
window?.makeKeyAndVisible()
handleOpenAppMessage(webpageURL: nil)
}
}