【问题标题】:Get list of all installed apps获取所有已安装应用的列表
【发布时间】:2011-11-05 18:51:18
【问题描述】:

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

【问题讨论】:

    标签: objective-c ios jailbreak


    【解决方案1】:

    你可以使用这个代码sn-p:

     #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
    

    【讨论】:

    • 这不是私有 API,但我们可以访问私有文件夹。 Apple 将拒绝您的应用程序。此代码仅用于越狱的 iPhone。
    • @Fedorchuk,我怎样才能从普通的 iOS 设备获取这个已安装的应用程序列表,我的意思是没有越狱的 iPhone,请帮我这样做。
    • 没有越狱的 iPhone 你不能这样做。
    • 为什么总是返回“找不到已安装的应用plist”
    • @Funny:您可能正在尝试使用 iOS 8。这仅适用于以前的版本,因为该 plist 不再存在。
    【解决方案2】:

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

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

    【讨论】:

    • 这里只显示预装的应用和cydia应用,我说的是应用商店应用。
    • 尝试mobile用户的应用程序文件夹然后:/private/var/mobile/Applications
    • @BjörnMarschollek:非常感谢。我帮了我很多。
    • 原始答案在 iOS 8 中不起作用(缺少那个 plist),所以这个答案是迄今为止最好的。
    【解决方案3】:

    经过一番研究,我发现了一个名为iHasApp 的框架。这是返回带有应用名称、标识符和图标的字典的好方法:Finding out what Apps are installed

    【讨论】:

      【解决方案4】:

      还有AppList library,它会为你做所有的脏活: rpetrich/AppList 它被用于很多越狱调整,所以我不知道为什么以前没有在这里建议。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-01-14
        • 2010-11-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-04
        • 2011-05-05
        相关资源
        最近更新 更多