【发布时间】:2011-06-04 14:55:32
【问题描述】:
是否可以通过编程方式找出我的 iOS 设备上安装的所有应用程序的名称? 是否有任何 API 可用?
感谢您的帮助
【问题讨论】:
标签: iphone objective-c ios
是否可以通过编程方式找出我的 iOS 设备上安装的所有应用程序的名称? 是否有任何 API 可用?
感谢您的帮助
【问题讨论】:
标签: iphone objective-c ios
不,由于沙盒环境,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 库。
【讨论】:
试试这个,它甚至可以在非越狱设备上工作:
#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 对象的数组。
下面是一个代码 sn-p,它会打印您设备中安装的所有应用程序的名称。
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>。
【讨论】: