为了账号安全,请及时绑定邮箱和手机立即绑定

获取所有已安装应用程序的列表

获取所有已安装应用程序的列表

iOS
慕标5832272 2019-11-12 10:34:12
我想获取所有已安装应用程序的列表(NSArray)。我的应用程序是一个越狱应用程序,位于/ Applications中,因此Sandbox在那里没有问题。有没有办法获取应用商店应用列表?我已经在其他应用程序(激活器,SBSettings ...)中看到了这一点。我不知道如何执行此操作,因为所有应用程序沙箱均具有大量代码,因此我不知道如何访问沙箱中的.app文件夹。
查看完整描述

3 回答

?
慕姐4208626

TA贡献1852条经验 获得超7个赞

您可以使用以下代码段:


 #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


查看完整回答
反对 回复 2019-11-12
?
慕的地8271018

TA贡献1796条经验 获得超4个赞

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


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


查看完整回答
反对 回复 2019-11-12
  • 3 回答
  • 0 关注
  • 977 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信