一:iOS 8 以后可以通過<code>MobileCoreService</code> 的私有 API獲取 iOS 設(shè)備上安裝的所有應(yīng)用。(iOS11后失效)
會有審核被拒的風(fēng)險帚豪,謹(jǐn)慎使用次乓。
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需要設(shè)置白名單,大伙兒還要在plist設(shè)置负间。
部分URL schemes名單:https://www.zhihu.com/question/19907735