// Declaration
BOOL APCheckIfAppInstalled(NSString *bundleIdentifier); // Bundle identifier (eg. com.apple.mobilesafari) used to track apps

// Implementation

BOOL APCheckIfAppInstalled(NSString *bundleIdentifier)
{
    static NSString *const cacheFileName = @"com.apple.mobile.installation.plist";
    NSString *relativeCachePath = [[@"Library" stringByAppendingPathComponent: @"Caches"] stringByAppendingPathComponent: cacheFileName];
    NSDictionary *cacheDict = nil;
    NSString *path = nil;
    // Loop through all possible paths the cache could be in
    for (short i = 0; 1; i++)
    {

        switch (i) {
            case 0: // Jailbroken apps will find the cache here; their home directory is /var/mobile
                path = [NSHomeDirectory() stringByAppendingPathComponent: relativeCachePath];
                NSLog(@"%@", path);
                break;
            case 1: // App Store apps and Simulator will find the cache here; home (/var/mobile/) is 2 directories above sandbox folder
                path = [[NSHomeDirectory() stringByAppendingPathComponent: @"../.."] stringByAppendingPathComponent: relativeCachePath];
                NSLog(@"%@", path);
                break;
            case 2: // If the app is anywhere else, default to hardcoded /var/mobile/
                path = [@"/var/mobile" stringByAppendingPathComponent: relativeCachePath];
                NSLog(@"%@", path);
                break;
            default: // Cache not found (loop not broken)
                return NO;
            break; 
        }

        BOOL isDir = NO;
        if ([[NSFileManager defaultManager] fileExistsAtPath: path isDirectory: &isDir] && !isDir) // Ensure that file exists
            cacheDict = [NSDictionary dictionaryWithContentsOfFile: path];

        if (cacheDict) // If cache is loaded, then break the loop. If the loop is not "broken," it will return NO later (default: case)
            break;
    }

    NSLog(@"file find success");

    NSDictionary *system = [cacheDict objectForKey: @"System"]; // First check all system (jailbroken) apps
    if ([system objectForKey: bundleIdentifier]) return YES;
    NSDictionary *user = [cacheDict objectForKey: @"User"]; // Then all the user (App Store /var/mobile/Applications) apps
    if ([user objectForKey: bundleIdentifier]) return YES;

    // If nothing returned YES already, we'll return NO now
    return NO;
}

- (void)viewDidLoad
{
    NSArray *bundles2Check = [NSArray arrayWithObjects: @"com.apple.mobilesafari", @"com.yourcompany.yourselfmadeapp", @"com.blahblah.nonexistent", nil];
    for (NSString *identifier in bundles2Check)
        if (APCheckIfAppInstalled(identifier))
            NSLog(@"App installed: %@", identifier);
        else
            NSLog(@"App not installed: %@", identifier);
    [super viewDidLoad];
}

我想检查iPhone 4上安装的应用程序,但找不到正确的路径。 /var/mobile/Library/Caches/com.apple.mobile.installation.plist

它正在使用我的越狱iPad 2,但在我的iPhone 4上不工作。

苹果是否在com.apple.mobile.installation.plist上更改了?

非常感谢

有帮助吗?

解决方案

由于Apple应用程序沙箱,您无法在应用程序自己的目录(沙箱)以外查询任何内容。

这将在狱卒破损的设备上使用,因为它可以从操作系统中删除应用程序沙盒功能。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top