[英]Finding list of installed apps on iphone
是否可以通過編程方式找出我的 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 資料庫。
試試這個,它甚至可以在非越獄設備上工作:
#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>
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.