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

Jon*_*asG 26 objective-c jailbreak ios

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

Igo*_*gor 14

您可以使用此代码段:

 #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
Run Code Online (Sandbox Code Playgroud)

  • 这不是私有API,但我们可以访问私人文件夹.Apple将拒绝您的应用.仅将此代码用于越狱iPhone. (5认同)
  • 没有越狱的iPhone,你不能这样做. (3认同)
  • @Fedorchuk,我怎么能从普通的iOS设备上获得这个安装的应用程序列表,我的意思是没有越狱的iPhone,PLZ帮我做到这一点. (2认同)

Bjö*_*lek 7

在越狱的iPhone上,您只需阅读该/Applications文件夹即可.所有安装的应用程序都在那 只需列出/Applications使用中的目录NSFileManager:

NSArray *appFolderContents = [[NSFileManager defaultManager] directoryContentsAtPath:@"/Applications"];
Run Code Online (Sandbox Code Playgroud)