How to detect that the app is running on a jailbroken device? [duplicate]

I have just released my app for iOS, but I'm not sure how to make my app safe from being used by jailbrakers.

Can I do something to prevent my app working on jailbroken devices?


You can detect through code that if the app is running on a jail broken device or not. Through that way you can pop up an alert and close the app. You can do whatever you want to do. Here is a tutorial for it:

http://thwart-ipa-cracks.blogspot.com/2008/11/detection.html

and here is a Stack Overflow post:

How do I detect that an iOS app is running on a jailbroken phone?

Also, if you want a complete solution, you can see in tapjoy sdk code. They are detecting jailbroken iPhone. Here is tapjoy URL https://www.tapjoy.com/


Check for these paths

+ (BOOL)isJailBroken {
#ifdef TARGET_IPHONE_SIMULATOR
    return NO;
#endif

    NSArray *paths = @[@"/bin/bash",
                       @"/usr/sbin/sshd",
                       @"/etc/apt",
                       @"/private/var/lib/apt/",
                       @"/Applications/Cydia.app",
                       ];

    for (NSString *path in paths) {
        if ([self fileExistsAtPath:path]) {
            return YES;
        }
    }

    return NO;
}


+ (BOOL)fileExistsAtPath:(NSString *)path {
    FILE *pFile;
    pFile = fopen([path cStringUsingEncoding:[NSString defaultCStringEncoding]], "r");
    if (pFile == NULL) {
        return NO;
    }
    else
        fclose(pFile);
    return YES;
}

Additionally, you can take a look https://github.com/OneSignal/OneSignal-iOS-SDK/blob/master/iOS_SDK/OneSignalSDK/Source/OneSignalJailbreakDetection.m


Try to find a file which cydia or jailbroken device create. Or try to write in a file outside the app's blackbox. If you succeed to do that, the device is compromised/jailbroken :)

- (BOOL)jailbroken
{
    NSFileManager * fileManager = [NSFileManager defaultManager];
    return [fileManager fileExistsAtPath:@"/private/var/lib/apt/"];
}

-(BOOL) isJailbroken
{
#if TARGET_IPHONE_SIMULATOR
return NO;
#else
FILE *f = fopen("/bin/bash", "r");
if (errno == ENOENT)
{
    // device is NOT jailbroken
    fclose(f);
    NSLog(@"no");
    return NO;
}
else {
    // device IS jailbroken
    fclose(f);
    NSLog(@"yes");
    return YES;

}
#endif
}