其实就是iOS11之前获取App列表的代码,只不过iOS11及之后的版本在非越狱手机上无法使用这个API获取了,但是越狱手机不受限制,依然可以用
+ (void)installedApplications {
Class lsawsc = objc_getClass("LSApplicationWorkspace");
NSObject* workspace = [lsawsc performSelector:NSSelectorFromString(@"defaultWorkspace")];
NSArray *apps = [workspace performSelector:NSSelectorFromString(@"allInstalledApplications")];
Class LSApplicationProxy_class = objc_getClass("LSApplicationProxy");
for (int i = 0; i < apps.count; i++) {
NSObject *temp = apps[i];
if ([temp isKindOfClass:LSApplicationProxy_class]) {
NSString *appBundleId = [temp performSelector:NSSelectorFromString(@"applicationIdentifier")];
NSString *appName = [temp performSelector:NSSelectorFromString(@"localizedName")];
NSString * type = [temp performSelector:NSSelectorFromString(@"applicationType")];
NSString * shortVersionString = [temp performSelector:NSSelectorFromString(@"shortVersionString")];
NSString * containerURL = [[temp performSelector:NSSelectorFromString(@"containerURL")] path];
NSString * resourcesDirectoryURL = [[temp performSelector:NSSelectorFromString(@"resourcesDirectoryURL")] path];
NSString * bundleExecutable = [temp performSelector:NSSelectorFromString(@"bundleExecutable")];
NSLog(@"应用类型: %@", type);
NSLog(@"BundleId: %@", appBundleId);
NSLog(@"Name: %@", appName);
NSLog(@"Version: %@", shortVersionString);
NSLog(@"沙盒路径: %@", containerURL);
NSLog(@"App包路径: %@", resourcesDirectoryURL);
NSLog(@"TargetName: %@", bundleExecutable);
NSLog(@"=============================================");
}
}
}
获取更详细的信息
+ (void)listApps {
id space = [NSClassFromString(@"LSApplicationWorkspace") performSelector:@selector(defaultWorkspace)];
NSArray *plugins = [space performSelector:@selector(installedPlugins)];
NSMutableSet *list = [[NSMutableSet alloc] init];
for (id plugin in plugins) {
id bundle = [plugin performSelector:@selector(containingBundle)];
if (bundle)
[list addObject:bundle];
}
int a = 1;
for (id plugin in list) {
NSLog(@"================= %d =================",a);
a++;
NSLog(@"bundleIdentifier =%@", [plugin performSelector:@selector(bundleIdentifier)]);//bundleID
NSLog(@"applicationDSID =%@", [plugin performSelector:@selector(applicationDSID)]);
NSLog(@"applicationIdentifier =%@", [plugin performSelector:@selector(applicationIdentifier)]);
NSLog(@"applicationType =%@", [plugin performSelector:@selector(applicationType)]);
NSLog(@"dynamicDiskUsage =%@", [plugin performSelector:@selector(dynamicDiskUsage)]);
NSLog(@"itemID =%@", [plugin performSelector:@selector(itemID)]);
NSLog(@"itemName =%@", [plugin performSelector:@selector(itemName)]);
NSLog(@"minimumSystemVersion =%@", [plugin performSelector:@selector(minimumSystemVersion)]);
NSLog(@"requiredDeviceCapabilities =%@", [plugin performSelector:@selector(requiredDeviceCapabilities)]);
NSLog(@"sdkVersion =%@", [plugin performSelector:@selector(sdkVersion)]);
NSLog(@"shortVersionString =%@", [plugin performSelector:@selector(shortVersionString)]);
NSLog(@"sourceAppIdentifier =%@", [plugin performSelector:@selector(sourceAppIdentifier)]);
NSLog(@"staticDiskUsage =%@", [plugin performSelector:@selector(staticDiskUsage)]);
NSLog(@"teamID =%@", [plugin performSelector:@selector(teamID)]);
NSLog(@"vendorName =%@", [plugin performSelector:@selector(vendorName)]);
}
}
网友评论