iOS获取手机上安装的APP的名称和版本
2017-02-27 本文已影响1921人
牛小牛很牛
一:iOS 8 以后可以通过<code>MobileCoreService</code> 的私有 API获取 iOS 设备上安装的所有应用。(iOS11后失效)
会有审核被拒的风险,谨慎使用。
Class cls = NSClassFromString(@"LSApplicationWorkspace");
id s = [(id)cls performSelector:NSSelectorFromString(@"defaultWorkspace")];
NSArray *array = [s performSelector:NSSelectorFromString(@"allInstalledApplications")];
NSLog(@"================");
for (id item in array) {
NSLog(@"%@",[item performSelector:NSSelectorFromString(@"applicationIdentifier")]);
NSLog(@"%@",[item performSelector:NSSelectorFromString(@"bundleIdentifier")]);
NSLog(@"%@",[item performSelector:NSSelectorFromString(@"bundleVersion")]);
NSLog(@"%@",[item performSelector:NSSelectorFromString(@"shortVersionString")]);
}
NSLog(@"================");
二:利用URL schemes判断手机是否安装某app。
//判断本地是否有淘宝App
NSURL * myURL_APP_A = [NSURL URLWithString:@"taobao://"];
if ([[UIApplication sharedApplication] canOpenURL:myURL_APP_A]) {
NSLog(@"canOpenURL");
[[UIApplication sharedApplication] openURL:myURL_APP_A];
}
else{
NSLog(@"淘宝未安装");
}
提醒下:iOS9需要设置白名单,大伙儿还要在plist设置。
URL schemes.png
部分URL schemes名单:https://www.zhihu.com/question/19907735