How do I detect that an iOS app is running on a jailbroken phone?

后端 未结 17 1313
情书的邮戳
情书的邮戳 2020-11-22 10:48

If I want my app to behave differently on a jailbroken iPhone, how would I go about determining this?

17条回答
  •  抹茶落季
    2020-11-22 11:21

    Here's my solutions: Step 1

    extension UIDevice {
        func isJailBroken() -> Bool {
            let cydiaPath = "/Applications/Cydia.app"
            let aptPath = "/private/var/lib/apt/"
            if FileManager.default.fileExists(atPath: cydiaPath) || FileManager.default.fileExists(atPath: aptPath) {
                return true
            }
            return false
        }
    }
    

    Step 2: Call it inside viewDidLoad() inside your launch screen view controller(or whatever VC you are calling for the first time):

           // show a blank screen or some other view controller
           let viewController = UIDevice.current.isJailBroken() ? JailBrokenViewController() : NextViewController()
           self.navigationController?.present(viewController, animated: true, completion:nil)
    

提交回复
热议问题