views:

4037

answers:

4

If I want my app to behave differently on a jailbroken iPhone, how would I go about determining this? I thought someone had asked this question before, but I cannot seem to find it now.

+2  A: 

I'd suggest looking for files that aren't present on a "vanilla" iPhone. All jailbreak kits I've seen install ssh. That might be a good indicator of a jailbroken phone.

Gordon Wilson
ssh is never installed automatically, users must install it themselves.
chpwn
I haven't really kept up with the jailbreak scene. But as I recall, when I wrote this (Jan '09), Ziphone and others installed ssh and the bsd subsystem by default. Perhaps that's no longer true.
Gordon Wilson
+13  A: 

It depends what you mean by jailbreak. In the simple case, you should be able to see if Cydia is installed and go by that - something like

NSString *filePath = @"/Applications/Cydia.app";
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
   // do something useful
}

For hacked kernels, it's a little (lot) more involved.

wisequark
Wouldn't it be enough to look for _any_ file/dir outside your sandbox? Like /etc?
Rhythmic Fistman
Note that not all users have Cydia installed -- this is not a good check, and you should rather check for something like /bin/bash that /all/ users /will/ have.
chpwn
Where does apt store its info? Or could I just call a system() command and find out. I want to find out if they have certain apps, and if they have them, then restrict the app
ckrames1234
+15  A: 

Checking if the kernel is broken isn't THAT much more involved.

Jailbreaking makes the kernel's signature check of signed code always report that code is signed correctly, unbroken phones cannot run code with a bad signature.

So, include a separate executable in the app with a bad signature. It could just be a 3-line program that has main() and a return value. Compile the executable without code signing (turn it off in Project Settings->Build) and sign it with a different key using the "codesign" commandline utility.

Have your app exec the separate executable. If your program can't get the return value when running the separate executable with the bad sig, it's definitely jailed. If the separate executable returns A-OK, the phone is definitely jailbroken.

fonik
Can you get a (sub-)executable whose signature is invalid like that through the App Store?
fbrereto
+2  A: 

Did any one got His/her app rejected by using this code in their code?

    NSString *filePath =
    @"/Applications/Cydia.app";
    if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {   
 // do something useful 
    }

And also what if i search for more concrete apps like Photos App. ?

jAmi