-1

i'm trying to get the list of all the installed apps on an iPhone (jailbroken) and then make a list of them in a UITableView with their icons... is it possible? thanks

Cykey
  • 21
  • 1

3 Answers3

1

their is a way to check if an application is installed or not. Sometimes you may want to check if a specific app is installed on the device, in case you use custom URL schemes that require some other app to be installed (you could just gray out/disable some buttons then). Unfortunately, Apple apparently does not have any function that checks this for you, so I whipped one up. It does not enumerate every single app, instead it uses the MobileInstallation cache which is always up-to-date with SpringBoard and holds the Info dictionaries of all apps installed. Although you're not "supposed" to access the cache, it's readable my App Store apps. Here is my code which at least works perfectly fine with the Simulator:

        // 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];
                        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];
                        break;
                    case 2: // If the app is anywhere else, default to hardcoded /var/mobile/
                        path = [@"/var/mobile" stringByAppendingPathComponent: relativeCachePath];
                        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;
            }

            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;
        }

Here is an example of this, assuming that your app is named "yourselfmadeapp" and is an app in the app store.

Code:

        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);

Log Output:

Code:

        2009-01-30 12:19:20.250 SomeApp[266:20b] App installed: com.apple.mobilesafari

        2009-01-30 12:19:20.254 SomeApp[266:20b] App installed: com.yourcompany.yourselfmadeapp

        2009-01-30 12:19:20.260 SomeApp[266:20b] App not installed: com.blahblah.nonexistent
0

NSString *rootAppPath = @"/Applications";

NSArray *listApp = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:rootAppPath error:nil];

NSLog(@"%@",listApp);

This is one of the way to get all installed app and then use this array to display in tableview

Hitesh Vaghela
  • 1,635
  • 1
  • 11
  • 11
0

It's possible, just take a look at My3G. I have no idea how to do so, though.

Jack Humphries
  • 13,056
  • 14
  • 84
  • 125