利用私人的API獲得手機上所安裝的所有應用資訊(包括版本,名稱,bundleID,類型),apibundleid
MobileCoreService這個系統的庫,裡面有個私人的類LSApplicationWorkspace
,利用運行時可以獲得私人類裡面的方法,- (id)allInstalledApplications; 該方法能夠獲得裝置上所有的應用資訊,包括系統的和使用者的應用
獲得的應用的資訊是一個類對象LSApplicationProxy,該對象裡面有方法獲得app的版本,名稱,bundleID,類型
好了直接上代碼首先引入標頭檔#include <objc/runtime.h>
- (void)getAllApps{ //擷取手機上所有的app Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace"); NSObject *workspace = [LSApplicationWorkspace_class performSelector:@selector(defaultWorkspace)]; NSArray *apps = [workspace performSelector:@selector(allInstalledApplications)]; Class LSApplicationProxy_class = objc_getClass("LSApplicationProxy"); for (int i = 0; i < apps.count; i++) { NSObject *temp = apps[i]; if ([temp isKindOfClass:LSApplicationProxy_class]) { //應用的bundleId NSString *appBundleId = [temp performSelector:NSSelectorFromString(@"applicationIdentifier")]; //應用的名稱 NSString *appName = [temp performSelector:NSSelectorFromString(@"localizedName")]; //應用的類型是系統的應用還是第三方的應用 NSString * type = [temp performSelector:NSSelectorFromString(@"applicationType")]; //應用的版本 NSString * shortVersionString = [temp performSelector:NSSelectorFromString(@"shortVersionString")]; NSLog(@"類型=%@應用的BundleId=%@ ++++應用的名稱=%@版本號碼=%@",type,appBundleId,appName,shortVersionString); } } }
這裡附上MobileCoreServices裡面的標頭檔https://github.com/nst/iOS-Runtime-Headers/tree/master/Frameworks/MobileCoreServices.framework