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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7226406/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 21:17:12  来源:igfitidea点击:

Get list of all installed apps

objective-ciosjailbreak

提问by JonasG

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.

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

采纳答案by Igor

You can use this code snippet:

您可以使用此代码片段:

 #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

回答by Bj?rn Marschollek

On jailbroken iPhones, you can just read the /Applicationsfolder. All installed applications go there. Just list the directories in /Applicationsusing NSFileManager:

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

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

回答by JonasG

After some research I have found a framework called iHasApp. Here is a good solution to return a dictionary with app name, identifier and icon: Finding out what Apps are installed

经过一番研究,我找到了一个名为iHasApp的框架。这是返回带有应用程序名称、标识符和图标的字典的一个很好的解决方案:找出安装了哪些应用程序

回答by newenglander

There's also the AppList library, which will do all of the dirty work for you: rpetrich/AppListIt's used in a lot of Jailbreak tweaks, so I don't know why it wasn't suggested here before.

还有AppList library,它将为您完成所有肮脏的工作: rpetrich/AppList它用于许多越狱调整,所以我不知道为什么之前没有在这里建议它。

One way to get just AppStore apps would be to check the value of isSystemApplicationfor each app returned in the list. Those with the value set to NOare regular AppStore apps. There's also a function applicationsFilteredUsingPredicate:predicate, so perhaps it would even be possible to filter the list beforehand.

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