繁体   English   中英

以编程方式列出 iPhone 上所有已安装的应用程序?

[英]Listing all installed apps on iPhone Programmatically?

我需要在编码的帮助下列出 iPhone 上所有已安装的应用程序。 我正在使用越狱的 iPhone。 我使用了 ihasapp API,但它没有显示所有已安装应用程序的完整列表。 请帮我写代码。

我得到了iPhone中所有已安装应用程序的列表。 它使用私有框架,但不是越狱设备。 在代码段下方进行监视。

#include <objc/runtime.h>

    Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
    SEL selector=NSSelectorFromString(@"defaultWorkspace");
    NSObject* workspace = [LSApplicationWorkspace_class performSelector:selector];

    SEL selectorALL = NSSelectorFromString(@"allApplications");
    NSLog(@"apps: %@", [workspace performSelector:selectorALL]);

我已经尝试过此代码,并且在iOS9上运行良好。

有一个专用API SBSCopyApplicationDisplayIdentifiers

签名如下

CFArrayRef SBSCopyApplicationDisplayIdentifiers(仅布尔有效,布尔可调试);

如果您链接到SpringboardServices框架并使用它,它将返回已安装应用程序的列表。

更新1

这是从此处复制的用法示例

CFArrayRef SBSCopyApplicationDisplayIdentifiers(bool onlyActive, bool debuggable);

int main() {
    char buf[1024];
    CFArrayRef ary = SBSCopyApplicationDisplayIdentifiers(false, false);
    for(CFIndex i = 0; i < CFArrayGetCount(ary); i++) {
        CFStringGetCString(CFArrayGetValueAtIndex(ary, i),buf, sizeof(buf), kCFStringEncodingUTF8);
        printf("%s\n", buf);
    }
    return 0;
}

不要忘记链接到最流行的框架SpringboardServices。

我自己使用AppList库来获取所有已安装应用程序的列表。 它使用私有框架,因此它也仅用于越狱。 https://github.com/rpetrich/AppList上进行检查。

更新:@Nate关于这个已经被询问和回答的问题是正确的。 检出: 获取所有已安装应用程序的列表

我进行了大量搜索以获取iOS 11上已安装的应用程序列表。但是有代码可以检查此设备上当前安装的应用程序。

//If the device is iOS11
if ([[UIDevice currentDevice].systemVersion floatValue] >= 11.0) {
    NSBundle *container = [NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/MobileContainerManager.framework"];
    if ([container load]) {
        Class appContainer = NSClassFromString(@"MCMAppContainer");

        id test = [appContainer performSelector:@selector(containerWithIdentifier:error:) withObject:bundleId withObject:nil];
        NSLog(@"%@",test);
        if (test) {
            return YES;
        } else {
            return NO;
        }
    }
    return NO;

}

尝试这个。

NSArray *appList = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"/Applications" error:nil];
NSLog(@"%@",appList);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM