在iPhone上查找安装的应用程序列表
是否可以编程的方式find我的iOS设备上安装的所有应用程序的名称? 有没有可用的API?
谢谢您的帮助
不,iOS应用程序由于沙盒环境而无法访问/关于其他应用程序的信息。
是的,有可能获得所有安装的应用程序的列表
-(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
Dictionary
包含所有与系统有关的应用程序列表,而user
Dictionary
包含其他应用程序信息。
不是从设备。 但是,从桌面上,你可以偷看到iTunes资料库。
有没有越狱设备做到这一点,而不是让你的应用程序被拒绝。
1.获取当前正在运行的进程列表看到这个答案。 您将需要从进程名称转换为应用程序名称。
2.检查是否有任何应用程序使用UIApplicationDelegate canOpenURL注册了唯一的URLscheme。 有几个网站编目已知的url计划, 这是最好的。
如果某个应用程序当前没有运行,并且没有注册自定义urlscheme,那么这些方法将不会检测到该scheme。 我有兴趣听到应用程序商店允许比这更好的方法。
试试这个,即使没有越狱设备,它也能工作:
#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
您可以通过使用canOpenURL
方法检查应用程序是否安装,或者通过检查后台进程并将其与您感兴趣的应用程序的名称进行匹配来完成。
您可以使用运行时目标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>
。