简体   繁体   中英

Finding list of installed apps on iphone

Is it possible to programatically find out name of all apps installed on my iOS device ? Is there any API available for same ?

Thanks for the help

不,由于沙盒环境,iOS 应用程序无法访问其他应用程序的信息/关于其他应用程序的信息。

Yes it is possible to get list of all installed app

-(void) allInstalledApp
{    
    NSDictionary *cacheDict;

    NSDictionary *user;

    static NSString *const cacheFileName = @"com.apple.mobile.installation.plist";

    NSString *relativeCachePath = [[@"Library" stringByAppendingPathComponent: @"Caches"] stringByAppendingPathComponent: cacheFileName];

    NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent: @"../.."] stringByAppendingPathComponent: relativeCachePath];

    cacheDict    = [NSDictionary dictionaryWithContentsOfFile: path];

    user = [cacheDict objectForKey: @"User"];

    NSDictionary *systemApp=[cacheDict objectForKey:@"System"];
}   

systemApp Dictionary contains the list of all system related app and user Dictionary contains other app information.

There are ways to do this without a jailbroken device and not get your app rejected.
1. get a list of currently running processes see this SO answer. You will need to translate from process name to app name.
2. Check to see if any apps have registered a unique URL scheme with UIApplicationDelegate canOpenURL. There are a few sites cataloging known url schemes, this is the best one.

If an app is not currently running and does not register a custom url scheme then it will not be detected by these methods. I am interested in hearing a method that will be allowed in the app store that works better than this.

Not from the device. However, from the desktop you could peek into the iTunes library.

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]);//will give you all **Bundle IDS** of user's all installed apps

您可以通过使用canOpenURL方法检查应用程序是否已安装或检查后台进程并将它们与您感兴趣的应用程序名称进行匹配来实现。

You can use runtime objective c to get the list of all installed apps. It will give you an array of LSApplicationProxy objects.

Following is a code snippet that prints Name of all applications installed in your device.

Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
NSObject* workspace = [LSApplicationWorkspace_class performSelector:NSSelectorFromString(@"defaultWorkspace")];
NSMutableArray *array = [workspace performSelector:NSSelectorFromString(@"allApplications")];

NSMutableArray *mutableArray = [[NSMutableArray alloc] init];
for (id lsApplicationProxy in array) {
    if(nil != [lsApplicationProxy performSelector:NSSelectorFromString(@"itemName")]){
        [mutableArray addObject:[lsApplicationProxy performSelector:NSSelectorFromString(@"itemName")]];
    }
}
NSLog(@"********* Applications List ************* : \n %@",mutableArray);

Don't forget to include <objc/runtime.h> .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM