判断手机是否越狱,只需要调用以下方法(包含三种方式,三选一即可)
- (void) isJailBreak {
// 第一种方法
if ([[NSFileManager defaultManager] fileExistsAtPath:@"User/Applications/"]) {
NSLog(@"isJailBreak1: The device is jail broken!");
NSArray *appList = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"User/Applications/" error:nil];
NSLog(@"isJailBreak1: appList = %@", appList);
} else {
NSLog(@"isJailBreak1: The device is NOT jail broken!");
}
// 第二种方法
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"cydia://"]]) {
NSLog(@"isJailBreak2: The device is jail broken!");
} else {
NSLog(@"isJailBreak2: The device is NOT jail broken!");
}
// 第三种方法
NSArray *jailbreak_tool_paths = @[@"/Applications/Cydia.app",@"/Library/MobileSubstrate/MobileSubstrate.dylib", @"/bin/bash",@"/usr/sbin/sshd",@"/etc/apt"];
for (int i = 0; i < jailbreak_tool_paths.count; i++) {
if ([[NSFileManager defaultManager] fileExistsAtPath:jailbreak_tool_paths[i]]){
NSLog(@"isJailBreak3:The device is jail broken!");
return;
}
}
NSLog(@"isJailBreak3: The device is NOT jail broken!");
}