Class c =NSClassFromString(@"LSApplicationWorkspace");
id s = [(id)c performSelector:NSSelectorFromString(@"defaultWorkspace")];
NSArray * arr = [s performSelector:NSSelectorFromString(@"allInstalledApplications")];
for (id item in arr) {
NSLog(@"%@",[item performSelector:NSSelectorFromString(@"applicationIdentifier")]);
NSLog(@" app版本 %@",[item performSelector:NSSelectorFromString(@"shortVersionString")]);
NSLog(@" app build版本 %@",[item performSelector:NSSelectorFromString(@"bundleVersion")]);
NSLog(@" app 名字 %@",[item performSelector:NSSelectorFromString(@"localizedName")]);
}
获取到LSApplicationWorkspace的对象可以通过runtime得到该对象的所有属性和方法列表,然后可以自己测试获取相应的值
但是只能在iOS11以下版本才有效,iOS以上版本经测试该私有api已失效,并且由于使用了私有api提交到appStore的话可能会被拒。
网友评论