iOS获取手机上安装的APP的名称和版本

一: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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容