Can I get information about all the applications installed on the iPhone?

Can I get information (application icon, application name, application location) about all applications installed on iPhone / iPod?

+3
source share
4 answers

There is a way to check if the application is installed or not, however it violates the Sandbox rules, and Apple * may reject your application to use it. But this was done previously by other applications that are available on the App Store, so feel free to try it.

, , URL, - ( / ). , Apple, -, , , . , MobileInstallation, SpringBoard Info . "" , App Store. , Simulator 2.2.1: :

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

, , "yourselfmadeapp" . :

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

: :

2009-01-30 12: 19: 20.250 SomeApp [266: 20b] : com.apple.mobilesafari 2009-01-30 12: 19: 20.254 SomeApp [266: 20b] : com.yourcompany.yourselfmadeapp 2009-01-30 12: 19: 20.260 SomeApp [266: 20b] : com.blahblah.nonexistent

, , , Apple , MobileInstallation.plist, , , . !

http://www.iphonedevsdk.com/forum/iphone-sdk-development/37103-finding-out-what-apps-installed.html

+1

iPhone - :

NSString *rootAppPath = @"/Applications";
NSArray *listApp = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:rootAppPath error:nil];

Info.plist, .

UPDATE: , ( iOS8), /Applications

+1

, , Jailbroken, sandBox. , Info.plist .app, "/var/mobile/Applications/", "/var/mobile/Applications//*.app/Info.plist" .

- (void)scan
{

    NSString *pathOfApplications = @"/var/mobile/Applications";

    NSLog(@"scan begin");

    // all applications
    NSArray *arrayOfApplications = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:pathOfApplications error:nil];
    for (NSString *applicationDir in arrayOfApplications) {
        // path of an application
        NSString *pathOfApplication = [pathOfApplications stringByAppendingPathComponent:applicationDir];
        NSArray *arrayOfSubApplication = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:pathOfApplication error:nil];
        // seek for *.app
        for (NSString *applicationSubDir in arrayOfSubApplication) {
            if ([applicationSubDir hasSuffix:@".app"]) {// *.app
                NSString *path = [pathOfApplication stringByAppendingPathComponent:applicationSubDir];

                path = [path stringByAppendingPathComponent:@"Info.plist"];

                // so you get the Info.plist in the dict
                NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
                // code to analyzing the dict.
            }
        }
    }

    NSLog(@"scan end");
}

Here is an example of the contents of Info.plist. So, get the values ​​for any key you are interested in.

{
BuildMachineOSBuild = 11G63;
CFBundleDevelopmentRegion = "zh_CN";
CFBundleDisplayName = "\U4e50\U89c6\U5f71\U89c6HD";
CFBundleExecutable = LetvIpadClient;
CFBundleIconFile = "icon.png";
CFBundleIconFiles =     (
    "icon.png",
    "icon@2x.png"
);
CFBundleIdentifier = "com.letv.ipad.hdclient";
CFBundleInfoDictionaryVersion = "6.0";
CFBundleName = LetvIpadClient;
CFBundlePackageType = APPL;
CFBundleResourceSpecification = "ResourceRules.plist";
CFBundleShortVersionString = "3.1";
CFBundleSignature = "????";
CFBundleSupportedPlatforms =     (
    iPhoneOS
);
CFBundleURLTypes =     (
            {
        CFBundleURLName = "m.letv.com";
        CFBundleURLSchemes =             (
            letvIPad
        );
    }
);
CFBundleVersion = "3.1";
DTCompiler = "com.apple.compilers.llvmgcc42";
DTPlatformBuild = 10A403;
DTPlatformName = iphoneos;
DTPlatformVersion = "6.0";
DTSDKBuild = 10A403;
DTSDKName = "iphoneos6.0";
DTXcode = 0450;
DTXcodeBuild = 4G182;
LSRequiresIPhoneOS = 0;
MinimumOSVersion = "4.3";
UIDeviceFamily =     (
    2
);
"UILaunchImageFile~ipad" =     (
    "Default.png",
    "Default@2x.png"
);
UIPrerenderedIcon = 1;
UIStatusBarHidden = 1;
UISupportedInterfaceOrientations =     (
    UIInterfaceOrientationPortrait,
    UIInterfaceOrientationPortraitUpsideDown,
    UIInterfaceOrientationLandscapeLeft,
    UIInterfaceOrientationLandscapeRight
);
"UISupportedInterfaceOrientations~ipad" =     (
    UIInterfaceOrientationLandscapeRight,
    UIInterfaceOrientationLandscapeLeft
);
}
+1
source

try this, it will work even with non-jailbroken devices

#include <objc/runtime.h>
Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
SEL selector=NSSelectorFromString(@"defaultWorkspace");
NSObject* workspace = [LSApplicationWorkspace_class performSelector:selector];

SEL selectorALL = NSSelectorFromString(@"allApplications");
NSLog(@"apps: %@", [workspace performSelector:selectorALL]);
0
source

Source: https://habr.com/ru/post/1768352/


All Articles