I'm trying to make an app which onely works on jailbroken iDevices. I allready made a jailbreak detection:
([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"cydia://"]]);{
UIAlertView *cydiaisinstalled=[[UIAlertView alloc]initWithTitle:@"Cydia is installed!"
message:@"You can use Respring!"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[cydiaisinstalled show];
}}
But now I need the reverse thing. I need a NON JAILBREAK detection.
I need your help I need this for Weblin. Please Help me!!!
Try accessing any file outside the app's sandbox. For example:
BOOL IsDeviceJailbroken(void) {
#if TARGET_IPHONE_SIMULATOR
return NO;
#else
return [[NSFileManager defaultManager] fileExistsAtPath: @"/bin/bash"];
#endif
}
Note that having Cydia installed and having a jailbroken device are two different things.
I wrote a function that detects whether the device is jailbroken for another question, but it seems relevant here:
- (BOOL) isJailbroken() {
//If the app is running on the simulator
#if TARGET_IPHONE_SIMULATOR
return NO;
//If its running on an actual device
#else
BOOL isJailbroken = NO;
//This line checks for the existence of Cydia
BOOL cydiaInstalled = [[NSFileManager defaultManager] fileExistsAtPath:@"/Applications/Cydia.app"];
FILE *f = fopen("/bin/bash", "r");
if (!(errno == ENOENT) || cydiaInstalled) {
//Device is jailbroken
isJailbroken = YES;
}
fclose(f);
return isJailbroken;
#endif
}
This function uses two checks to see if the phone is jailbroken: it first checks if Cydia is installed. Not all jailbroken devices have Cydia installed, though most do, so I also check for the existence of bash, which also only appears on jailbroken devices. Note that this function will work in nearly all cases, but it's probably not 100%. The only people that don't have Cydia on their jailbroken iDevice are probably those that are experimenting with jailbroken devices and not using them for advantages like tweaks and themes.
OK thanks for all the answers but I found it out on my own. Here is the code:
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"cydia://"]]) {
//insert action if cydia is installed
}
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"cydia://"]] == NO) {
//insert action if Cydia is not installed
}
With this code you can detect any application on your idevice as long as the app has an URL scheme you can find most of the URL scheme here: http://handleopenurl.com
PS: You have to replace the green part whith your actions:)