关于C#:获取所有已安装应用的列表

Get list of all installed apps

我想获取所有已安装应用程序的列表(NSArray)。 我的应用程序是一个越狱应用程序,位于/ Applications中,因此Sandbox在那里没有问题。 有没有办法获取应用商店应用列表? 我已经在其他应用程序(Activator,SBSettings ...)中看到了这一点。 我不知道如何执行此操作,因为所有应用程序沙箱都具有大量代码,因此我不知道如何访问沙箱中的.app文件夹。


您可以使用以下代码段:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 #import"InstalledAppReader.h"

static NSString* const installedAppListPath = @"/private/var/mobile/Library/Caches/com.apple.mobile.installation.plist";

@interface InstalledAppReader()

-(NSArray *)installedApp;
-(NSMutableDictionary *)appDescriptionFromDictionary:(NSDictionary *)dictionary;

@end


@implementation InstalledAppReader

#pragma mark - Init
-(NSMutableArray *)desktopAppsFromDictionary:(NSDictionary *)dictionary
{
    NSMutableArray *desktopApps = [NSMutableArray array];

    for (NSString *appKey in dictionary)
    {
        [desktopApps addObject:appKey];
    }
    return desktopApps;
}

-(NSArray *)installedApp
{    
    BOOL isDir = NO;
    if([[NSFileManager defaultManager] fileExistsAtPath: installedAppListPath isDirectory: &isDir] && !isDir)
    {
        NSMutableDictionary *cacheDict = [NSDictionary dictionaryWithContentsOfFile: installedAppListPath];
        NSDictionary *system = [cacheDict objectForKey: @"System"];
        NSMutableArray *installedApp = [NSMutableArray arrayWithArray:[self desktopAppsFromDictionary:system]];

        NSDictionary *user = [cacheDict objectForKey: @"User"];
        [installedApp addObjectsFromArray:[self desktopAppsFromDictionary:user]];

        return installedApp;
    }

    DLOG(@"can not find installed app plist");
    return nil;
}

@end


在越狱的iPhone上,您只能读取/Applications文件夹。 所有已安装的应用程序都去了那里。 只需使用NSFileManager列出/Applications中的目录:

1
NSArray *appFolderContents = [[NSFileManager defaultManager] directoryContentsAtPath:@"/Applications"];


还有AppList library,它将为您完成所有肮脏的工作:
rpetrich / AppList
很多越狱调整中都使用了它,所以我不知道为什么以前不建议这样做。

仅获取AppStore应用程序的一种方法是检查列表中返回的每个应用程序的isSystemApplication值。 值设置为NO的是常规AppStore应用程序。 还有一个功能applicationsFilteredUsingPredicate:predicate,所以也许甚至可以事先过滤列表。


经过一番研究,我发现了一个名为iHasApp的框架。 这是一个返回带有应用程序名称,标识符和图标的词典的好方法:查找已安装的应用程序