获取所有已安装应用的列表 [英] Get list of all installed apps

查看:198
本文介绍了获取所有已安装应用的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to get a list of all installed apps(NSArray). My app is a jailbreak app and is located in/Applications so Sandbox is no problem there. Is there any way to get a list of app store apps? I've already seen this in other apps (Activator, SBSettings...). I have no idea how to do this, because all of the apps sandboxes have that huge code, so i don't know how it would be possible to access the .app folder inside the sandbox.

推荐答案

您可以使用此代码段:

 #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

这篇关于获取所有已安装应用的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆