★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公众号:山青咏芝(shanqingyongzhi)
➤博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/)
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:http://www.javashuo.com/article/p-pjagaual-mb.html
➤若是连接不是山青咏芝的博客园地址,则多是爬取做者的文章。
➤原文已修改更新!强烈建议点击原文地址阅读!支持做者!支持原创!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★html
目录:[Swift]通天遁地Swiftgit
本文将演示如何判断程序是否运行在越狱设备上。github
假如产品使用了内购功能,当运行在越狱设备时,可采起一些防护和安全提示措施。swift
在项目导航区,打开视图控制器的代码文件【ViewController.swift】数组
越狱设备因为没有沙盒做为保护,黑客能够对系统进行任意的修改,安全
苹果返回的内购付款凭证有多是虚假的,因此须要进行越狱设备的检测。微信
1 import UIKit 2 3 class ViewController: UIViewController { 4 5 override func viewDidLoad() { 6 super.viewDidLoad() 7 // Do any additional setup after loading the view, typically from a nib. 8 //在视图加载完成的方法中,经过一个判断语句, 9 //判断设备是否越狱。 10 if isJailBroken() 11 { 12 //当设备处于越狱状态时,在控制台输出相应的提示语句。 13 print("Your device has been jailbroken, please pay attention to the security of payment.") 14 } 15 else 16 { 17 print("Your device has not been jailbroken.") 18 } 19 } 20 21 //添加一个方法,用来检测设备是否越狱。 22 //并在方法的末尾,返回一个布尔结果。 23 func isJailBroken() -> Bool 24 { 25 //越狱设备一般会自动在应用程序目录下, 26 //安装一些特殊的软件。 27 //能够判断设备中是否包含这些程序, 28 //来判断该设备是否处于越狱状态。 29 let apps = ["/Applications/Cydia.app", 30 "/Applications/limera1n.app", 31 "/Applications/greenpois0n.app", 32 "/Applications/blackra1n.app", 33 "/Applications/blacksn0w.app", 34 "/Applications/redsn0w.app", 35 "/Applications/Absinthe.app"] 36 37 //添加一个循环语句,用来遍历应用程序的数组。 38 for app in apps 39 { 40 //经过文件管理器,判断在指定的目录下, 41 //是否存在对应的应用程序。 42 if(FileManager.default.fileExists(atPath: app)) 43 { 44 //若是存在的话,就表示当前设备属于越狱设备 45 return true 46 } 47 } 48 //若是找不到这些应用程序,则表示当前设备处于非越狱设备。 49 return false 50 } 51 52 override func didReceiveMemoryWarning() { 53 super.didReceiveMemoryWarning() 54 // Dispose of any resources that can be recreated. 55 } 56 }