1
This commit is contained in:
zeus
2025-08-02 07:07:59 +08:00
parent 4c4c6ac26a
commit ecf2feb429
4 changed files with 61 additions and 40 deletions
@@ -5,36 +5,50 @@ import Library
import Network
import UIKit
/// UUVPN
/// VPN
class ApplicationDelegate: NSObject, UIApplicationDelegate {
/// iOS 16+
private var profileServer: ProfileServer?
///
func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
// Libbox VPN
LibboxSetup(FilePath.sharedDirectory.relativePath, FilePath.workingDirectory.relativePath, FilePath.cacheDirectory.relativePath, false)
setup()
return true
}
///
private func setup() {
do {
//
try UIProfileUpdateTask.configure()
NSLog("setup background task success")
} catch {
NSLog("setup background task error: \(error.localizedDescription)")
}
//
Task {
if UIDevice.current.userInterfaceIdiom == .phone {
// iPhone
await requestNetworkPermission()
}
//
await setupBackground()
}
}
/// iOS 16+
private nonisolated func setupBackground() async {
if #available(iOS 16.0, *) {
do {
let profileServer = try ProfileServer()
profileServer.start()
// 线
await MainActor.run {
self.profileServer = profileServer
}
@@ -45,22 +59,23 @@ class ApplicationDelegate: NSObject, UIApplicationDelegate {
}
}
private nonisolated func requestNetworkPermission() async {
if await SharedPreferences.networkPermissionRequested.get() {
return
}
if !DeviceCensorship.isChinaDevice() {
await SharedPreferences.networkPermissionRequested.set(true)
return
}
URLSession.shared.dataTask(with: URL(string: "http://captive.apple.com")!) { _, response, _ in
if let response = response as? HTTPURLResponse {
if response.statusCode == 200 {
Task {
await SharedPreferences.networkPermissionRequested.set(true)
}
}
}
}.resume()
}
}
///
private nonisolated func requestNetworkPermission() async {
if await SharedPreferences.networkPermissionRequested.get() {
return
}
if !DeviceCensorship.isChinaDevice() {
await SharedPreferences.networkPermissionRequested.set(true)
return
}
URLSession.shared.dataTask(with: URL(string: "http://captive.apple.com")!) { _, response, _ in
if let response = response as? HTTPURLResponse {
if response.statusCode == 200 {
Task {
await SharedPreferences.networkPermissionRequested.set(true)
}
}
}
}.resume()
}
}