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

发布于 2024-12-02 03:31:12 字数 195 浏览 1 评论 0原文

我想获取所有已安装应用程序的列表(NSArray)。我的应用程序是越狱应用程序,位于/Applications 中,因此沙箱在那里没有问题。有什么方法可以获取应用商店应用程序列表吗?我已经在其他应用程序(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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

旧竹 2024-12-09 03:31:12

您可以使用以下代码片段:

 #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

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
隐诗 2024-12-09 03:31:12

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

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

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

NSArray *appFolderContents = [[NSFileManager defaultManager] directoryContentsAtPath:@"/Applications"];
淡淡绿茶香 2024-12-09 03:31:12

经过一番研究,我发现了一个名为 iHasApp 的框架。这是一个返回包含应用程序名称、标识符和图标的字典的好解决方案: 查看安装了哪些应用

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

绅刃 2024-12-09 03:31:12

还有 AppList 库,它将为您完成所有脏活:
rpetrich/AppList
它被用在很多越狱调整中,所以我不知道为什么以前没有在这里建议它。

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

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文