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是可以直接獲取應用列表的