SwiftPM Compatible Cocoapods Compatible macOS Versions Supported MIT License
A modern Swift wrapper for Apple's SystemExtensions framework that provides async/await support and simplified APIs for managing system extensions on macOS.
- π Async/await support - Modern Swift concurrency
- π± Simple API - Easy-to-use methods for common tasks
- π‘οΈ Error handling - Comprehensive error types and descriptions
- π Progress tracking - Real-time status updates
- π― Swift 5.10+ - Built for modern Swift
- π¦ SwiftPM - Multiple installation options
- macOS 10.15+
- Swift 5.10+
- Xcode 14.0+
dependencies: [ .package(url: "https://github.com/codingiran/SystemExtensionKit.git", from: "2.1.0") ]
import SystemExtensionKit // Activate system extension do { try await SystemExtension.activeSystemExtension() print("Extension activated successfully") } catch { print("Failed to activate: \(error.localizedDescription)") } // Check extension status let status = await SystemExtension.checkSystemExtensionStatus() switch status { case .installed: print("Extension is installed and running") case .waitingApproval: print("Extension needs user approval") case .notInstalled: print("Extension is not installed") case .unknown: print("Status unknown (macOS < 12.0)") } // Deactivate system extension do { try await SystemExtension.deactiveSystemExtension() print("Extension deactivated successfully") } catch { print("Failed to deactivate: \(error.localizedDescription)") }
class ExtensionManager: SystemExtensionRequestUpdating { func setupExtension() { // Set progress updater SystemExtension.requestUpdater = self Task { do { try await SystemExtension.activeSystemExtension() } catch { print("Extension activation failed: \(error)") } } } // MARK: - SystemExtensionRequestUpdating func systemExtensionRequest(_ request: SystemExtensionRequest, updateProgress progress: SystemExtensionRequest.Progress) { switch progress { case .submitting: print("Submitting extension request...") case .needsUserApproval: print("User approval required") case .completed: print("Extension request completed") case .willCompleteAfterReboot: print("Restart required to complete") case .failed(let error): print("Request failed: \(error.localizedDescription)") case .replacingExtension(let existing, let new): print("Replacing version \(existing) with \(new)") case .cancelExtension(let existing, let new): print("Canceling replacement of \(existing) with \(new)") } } }
// Force update extension try await SystemExtension.activeSystemExtension(forceUpdate: true) // Get extension properties (macOS 12.0+) if #available(macOS 12.0, *) { if let properties = try await SystemExtension.enabledSystemExtensionProperty() { print("Bundle ID: \(properties.bundleIdentifier)") print("Version: \(properties.bundleVersion)") print("Awaiting approval: \(properties.isAwaitingUserApproval)") } }
SystemExtensionKit provides comprehensive error types:
do { try await SystemExtension.activeSystemExtension() } catch SystemExtensionKit.ExtensionError.extensionNotExist { print("No system extension found in app bundle") } catch SystemExtensionKit.ExtensionError.extensionNeedReboot { print("System restart required") } catch SystemExtensionKit.ExtensionError.extensionSystemUnsupport { print("System version not supported") } catch { print("Other error: \(error.localizedDescription)") }
SystemExtensionKit is available under the MIT license. See the LICENSE file for more info.