diff --git a/Library/Discovery/NWSocket.swift b/ApplicationLibrary/Service/NWSocket.swift
similarity index 100%
rename from Library/Discovery/NWSocket.swift
rename to ApplicationLibrary/Service/NWSocket.swift
diff --git a/Library/Discovery/ProfileServer.swift b/ApplicationLibrary/Service/ProfileServer.swift
similarity index 79%
rename from Library/Discovery/ProfileServer.swift
rename to ApplicationLibrary/Service/ProfileServer.swift
index 596696e..2cd10d2 100644
--- a/Library/Discovery/ProfileServer.swift
+++ b/ApplicationLibrary/Service/ProfileServer.swift
@@ -1,6 +1,10 @@
import Foundation
import Libbox
+import Library
import Network
+#if canImport(UIKit)
+ import UIKit
+#endif
public class ProfileServer {
private var listener: NWListener
@@ -32,12 +36,21 @@ public class ProfileServer {
class ProfileConnection {
private let connection: NWSocket
+ #if os(iOS)
+ private var backgroundTaskID: UIBackgroundTaskIdentifier = .invalid
+ #endif
init(_ connection: NWConnection) {
self.connection = NWSocket(connection)
}
func process() async {
+ #if os(iOS)
+ beginBackgroundTask()
+ defer {
+ endBackgroundTask()
+ }
+ #endif
do {
try await writeProfilePreviewList()
} catch {
@@ -56,6 +69,26 @@ public class ProfileServer {
}
}
+ #if os(iOS)
+ private func beginBackgroundTask() {
+ backgroundTaskID = UIApplication.shared.beginBackgroundTask { [weak self] in
+ NSLog("profile server: background task expiring, cleaning up connection")
+ self?.connection.cancel()
+ self?.endBackgroundTask()
+ }
+ if backgroundTaskID != .invalid {
+ NSLog("profile server: background task started")
+ }
+ }
+
+ private func endBackgroundTask() {
+ guard backgroundTaskID != .invalid else { return }
+ NSLog("profile server: background task ended")
+ UIApplication.shared.endBackgroundTask(backgroundTaskID)
+ backgroundTaskID = .invalid
+ }
+ #endif
+
private func processMessage(_ data: Data) throws {
if data.count == 0 {
return
diff --git a/SFI/Info.plist b/SFI/Info.plist
index f720122..5a9f1a2 100644
--- a/SFI/Info.plist
+++ b/SFI/Info.plist
@@ -23,6 +23,11 @@
+ CFBundleLocalizations
+
+ en
+ zh_CN
+
CFBundleURLTypes
@@ -38,8 +43,6 @@
- ITSAppUsesNonExemptEncryption
-
NSApplicationServices
Advertises
@@ -65,6 +68,7 @@
UIBackgroundModes
fetch
+ processing
UTExportedTypeDeclarations
@@ -116,12 +120,5 @@
- CFBundleLocalizations
-
- en
- zh_CN
-
- CFBundleDevelopmentRegion
- en
diff --git a/sing-box.xcodeproj/project.pbxproj b/sing-box.xcodeproj/project.pbxproj
index 5b9090e..839af28 100644
--- a/sing-box.xcodeproj/project.pbxproj
+++ b/sing-box.xcodeproj/project.pbxproj
@@ -1960,6 +1960,7 @@
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = SFI/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "sing-box";
+ INFOPLIST_KEY_ITSAppUsesNonExemptEncryption = NO;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
@@ -2001,6 +2002,7 @@
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = SFI/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "sing-box";
+ INFOPLIST_KEY_ITSAppUsesNonExemptEncryption = NO;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;