在iPhone上查找已安装应用程序的列表

16

我能否编程方式找出我iOS设备上安装的所有应用程序名称?是否有相应的API可用?

感谢您的帮助。

7个回答

13

不,由于沙盒环境的限制,iOS应用程序无法访问其他应用程序的信息。


我找到了一个可行的解决方案,不确定苹果是否会接受!!!你有什么想法? - Unicorn
1
这是链接:http://www.iphonedevsdk.com/forum/iphone-sdk-development/22289-possible-retrieve-these-information.html - Unicorn
2
是的,该文件对移动用户来说是可读的,但是如果发现应用程序只能访问自己的沙盒,其他文件必须通过公共SDK访问,苹果可以(并且会)拒绝这样的应用程序。 - Nickolay Olshevsky
您可以在iPhone企业版上使用它,但不能确定是否能在App Store上使用。 - virata

4
是的,可以获取所有安装的应用程序列表。
-(void) allInstalledApp
{    
    NSDictionary *cacheDict;

    NSDictionary *user;

    static NSString *const cacheFileName = @"com.apple.mobile.installation.plist";

    NSString *relativeCachePath = [[@"Library" stringByAppendingPathComponent: @"Caches"] stringByAppendingPathComponent: cacheFileName];

    NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent: @"../.."] stringByAppendingPathComponent: relativeCachePath];

    cacheDict    = [NSDictionary dictionaryWithContentsOfFile: path];

    user = [cacheDict objectForKey: @"User"];

    NSDictionary *systemApp=[cacheDict objectForKey:@"System"];
}   

systemApp 字典 包含所有系统相关应用程序的列表,而 user 字典 则包含其他应用程序信息。


这是否还提供了开发者应用程序列表? - yunas
这对我也不起作用。收到的响应为 nil。请建议。 - jaydev
1
这仅适用于越狱设备,不适用于非越狱设备,对于非越狱设备,它返回nil。 - Mehul Thakkar
请查看此链接 https://github.com/danielamitay/iHasApp,文档链接https://www.ihasapp.com/documentation/Classes/iHasApp.html。 - Avinash Kashyap

2

并非从设备上进行操作,但是你可以从桌面上查看iTunes库。


你是在谈论编程方面的吗? 如果是,你能提供更多细节吗? - AmineG

2

有方法可以在不越狱设备的情况下实现,并且不会导致您的应用被拒绝。
1. 获取当前正在运行的进程列表,请参见 SO答案。 您需要将进程名称翻译为应用程序名称。
2. 检查是否有任何应用程序使用UIApplicationDelegate canOpenURL注册了唯一的URL方案。 有一些网站目录已知的URL方案,这个是最好的一个。

如果应用程序当前未运行并且未注册自定义URL方案,则这些方法将无法检测到它。 我很感兴趣听到一个能够在应用商店中允许的方法,比这更好。


1

尝试这个,即使是非越狱设备也可以使用:

#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]);//will give you all **Bundle IDS** of user's all installed apps

如何从中解析应用程序名称和包标识符?请帮助我。 - Vikash Rajput
@VikashRajput 我的答案已经100%测试过了。你将在上面代码的最后一行中获得所有应用程序(即Bundle IDs),但由于沙盒限制,你无法覆盖任何内容。不过,你可以通过谷歌搜索来解决这个问题。如果我的回答对你有帮助,请点赞 :)。 - Anurag Sharma
它将返回LSApplicationProxy类型对象的数组,但我无法获取bundle id作为NSString。您能否将bundle id解析为NSString? - Vikash Rajput
1
[workspace performSelector:selectorALL] objectAtIndexPath:0]; 打印这个,你会得到第一个索引,然后使用for循环并将其分离成字符串。 - Anurag Sharma

0
你可以使用运行时 Objective-C 获取所有已安装应用程序的列表。它将为您提供一个 LSApplicationProxy 对象数组。
以下是一个代码片段,打印您设备中安装的所有应用程序的名称。
Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
NSObject* workspace = [LSApplicationWorkspace_class performSelector:NSSelectorFromString(@"defaultWorkspace")];
NSMutableArray *array = [workspace performSelector:NSSelectorFromString(@"allApplications")];

NSMutableArray *mutableArray = [[NSMutableArray alloc] init];
for (id lsApplicationProxy in array) {
    if(nil != [lsApplicationProxy performSelector:NSSelectorFromString(@"itemName")]){
        [mutableArray addObject:[lsApplicationProxy performSelector:NSSelectorFromString(@"itemName")]];
    }
}
NSLog(@"********* Applications List ************* : \n %@",mutableArray);

不要忘记包含 <objc/runtime.h>

0
你可以通过使用canOpenURL方法来检查应用程序是否已安装,或者通过检查后台进程并将其与你感兴趣的应用程序名称进行匹配来实现。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接