Search code examples
iosobjective-cxcode5jailbreak

Jailbreak Detection


If I want to have an application run a command to check if a device is jailbroken, how would I go about doing that?

(This is the command I want to execute if the program can determine if Cydia is installed)

UIAlertView *jailbreakDetection = [[UIAlertView alloc]
                                   initWithTitle:@"Jailbreak Detected"
                                   message:@"This application will not run while a jailbreak is installed."
                                   delegate:nil
                                   cancelButtonTitle:nil
                                   otherButtonTitles:nil];

[jailbreakDetection show];

By showing this alert, the user cannot run the application as there is no way to stop the message from showing on the screen. I've looked into some similar questions, but none of them worked for me, for example, when I ran this code, I got an error "Expected identifier or '('". I'm running it in the NavigationController.m file, so that I will hit the user on initial application launch.

NSString *filePath = @"/Applications/Cydia.app";

if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
UIAlertView *jailbreakDetection = [[UIAlertView alloc]
                                  initWithTitle:@"Jailbreak Detected"
                                  message:@"This application will not run while a jailbreak is installed."
                                  delegate:nil
                                  cancelButtonTitle:nil
                                  otherButtonTitles:nil];

 [jailbreakDetection show];
}

What am I doing wrong with this? Should I be placing this in a separate file?


Solution

  • Your code does not compile because it is not part of a method or function. You have to move that code e.g. to viewDidLoad.

    (This answer refers only to the compiler error, not to the possible mechanisms of Jailbreaking detection.)