2

Can you say me what is false in this code? I like to check if cydia.app is installed on every launch and if Cydia is installed the Lable should change and a button should be enabled but nothing happens.

Here is the code:

NSString *filePath = @"/Applications/Cydia.app";
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]){
    Lable.text = @"You are jailbroken";
    Button.enabled = YES;
}

2 Answers2

3

You need to enclose both lines with parentheses if you want to enable the button, and remove the semicolon after the conditional. Basically, your code should look like this:

if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"cydia://"]]){
     Lable.text = @"You are jailbroken";
     Button.enabled = YES;
}

Otherwise, what you are currently using after the conditional statement, by inserting a semicolon, is actually a null statement. Even if you remove the semicolon, only the first line will be executed. Therefor, you need to remove the semicolon, and insert curly brackets to set the scope of the conditional.

Edit:

Perhaps you might need to try building the path instead of hardcoding it:

NSString* filePath = [NSSearchPathForDirectoriesInDomains(NSApplicationDirectory, NSUserDomainMask, YES) stringByAppendingPathComponent: @"cydia.app"];

If the file still doesn't exist, try to list the files and directories in the NSApplicationDirectory to see if the file actually exists, or you need to search elsewhere (maybe even a subfolder).

  • sorry i put in the false jailbreak detection but with your help it is the same as before:( –  Sep 10 '12 at 00:00
  • 1
    I found the code at my self if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"cydia://"]]) { lablered.text = @""; } if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"cydia://"]] == NO) { lablered.text = @"You are not jailbroken"; Button.enabled = NO; rebootbutton.enabled = NO; actionbutton.enabled = NO; } –  Oct 10 '12 at 20:50
1

Set some breakpoints in your code so that when you debug your code you can see what your conditional statement is evaluating to and depending on that, then see what is happening with the code in your if structure. In many cases, like this, simply setting breakpoints and quickly stepping over your code will lead you to your resolution faster than posting up a question on the Internet, not that people won't help you, but you won't be held up and can continue working.

Cheers.

Anil
  • 2,539
  • 6
  • 33
  • 42