iOS10及以下可以直接获取应用安装列表,到iOS11就只能通过私有方法判断是否安装某个应用,到iOS12私有方法也没有权限访问了
所以目前iOS12只能通过应用的相关插件判断是否安装某个应用了,大厂的一般都会有插件,小厂的可能没有插件(有更好的办法可以指教一下)
if ([[UIDevice currentDevice].systemVersion floatValue] >= 11.0) {
//iOS12间接获取办法
if ([[UIDevice currentDevice].systemVersion floatValue] >= 12.0){
Class lsawsc = objc_getClass("LSApplicationWorkspace");
NSObject* workspace = [lsawsc performSelector:NSSelectorFromString(@"defaultWorkspace")];
NSArray *plugins = [workspace performSelector:NSSelectorFromString(@"installedPlugins")]; //列出所有plugins
[plugins enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSString *pluginID = [obj performSelector:(@selector(pluginIdentifier))];
NSLog(@"%@",pluginID);
}];
}else{
//iOS11获取办法
NSBundle *container = [NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/MobileContainerManager.framework"];
if ([container load]) {
Class appContainer = NSClassFromString(@"MCMAppContainer");
id test = [appContainer performSelector:@selector(containerWithIdentifier:error:) withObject:BundleID withObject:nil];
NSLog(@"%@",test);
if (test) {
//YES;
} else {
//NO;
}
}else{
//NO
}
}
}else{
//iOS10及以下获取办法
Class lsawsc = objc_getClass("LSApplicationWorkspace");
NSObject* workspace = [lsawsc performSelector:NSSelectorFromString(@"defaultWorkspace")];
NSArray *appList = [workspace performSelector:@selector(allApplications)];
Class LSApplicationProxy_class = object_getClass(@"LSApplicationProxy");
for (LSApplicationProxy_class in appList)
{
//这里可以查看一些信息
NSString *bundleID = [LSApplicationProxy_class performSelector:@selector(applicationIdentifier)];
NSString *version = [LSApplicationProxy_class performSelector:@selector(bundleVersion)];
NSString *shortVersionString = [LSApplicationProxy_class performSelector:@selector(shortVersionString)];
if ([bundleID isEqualToString:BundleID]) {
return YES;
}
}
}
iOS10之后不能直接获取了,需要用到私有库,上store会有问题可以用到反射机制混淆加密字符串避免,注意好不要在代码中出现私有函数的字样。
iOS10是可以直接获取应用列表的