JailbreakDetector.swift

Swift

一个超级简单、可配置且(可选)详细的 iOS 越狱检测器。

JailbreakDetector 的设计目的不是为了阻止应用在越狱设备上运行,甚至不是为了 100% 准确地检测越狱。相反,它专注于检测一些常见的越狱迹象,并允许您查询结果以确定怀疑越狱的原因(这在调试越狱设备上意外行为时可能很有用)。

您还可以使用 JailbreakDetectorConfiguration 自定义越狱检测器的行为,以便更好地控制探测系统的哪些部分。

开始使用

对于基本用法,创建一个 JailbreakDetector 实例并调用 isJailbroken() 方法

import JailbreakDetector

let detector = JailbreakDetector()
if detector.isJailbroken() {
    print("This device might be jailbroken!")
}

如果您需要深入了解越狱检测器的结果,请使用 detectJailbreak() 方法,该方法返回一个 Result 枚举

let detector = JailbreakDetector()
switch detector.detectJailbreak() {
case .pass:
    print("Not jailbroken!")
case .fail(let reasons):
    print("Might be jailbroken because:")
    for reason in reasons {
        print("Reason: \(reason)")
    }
case .simulator:
    print("Running in the simulator!")
case .macCatalyst:
    print("Running on macOS!")
}

为了更精细地控制越狱检测器的行为,请使用 JailbreakDetectorConfiguration。注意:在大多数情况下,您应该按原样使用默认配置,或者将其作为基线,而不是从头开始初始化您自己的配置。

// Start with the default configuration.
var configuration = JailbreakDetectorConfiguration.default

// Enable logging.
configuration.loggingEnabled = true

// Disable halt after failure. When disabled, the jailbreak detector will
// continue with its checks even after encountering a failure,
// and the `Result.fail` case may include multiple failure reasons.
configuration.haltAfterFailure = false

// Initialize the jailbreak detector with the custom configuration.
let detector = JailbreakDetector(using: configuration)

安装

JailbreakDetector 通过 Swift Package Manager 提供。 要将 JailbreakDetector 与 SPM 一起使用,请添加 https://github.com/conmulligan/JailbreakDetector.swift.git 作为依赖项。

许可

JailbreakDetector 在 MIT 许可下可用。 有关更多信息,请参见 LICENSE 文件。