iOS13 中判断应用是否安装

网上有很多文章介绍了通过私有API方法判断是否安装的方式。在iOS7,8,9,10 通过LSApplicationWorkspac得到安装应用列表的方式得到所有应用的bundleID

代码如下 

Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");

NSObject* workspace = [LSApplicationWorkspace_class performSelector:@selector(defaultWorkspace)];

NSArray*allApplications = [workspace performSelector:@selector(allApplications)];

for(NSString*appStrinallApplications)

 {

NSString*app = [NSStringstringWithFormat:@"%@",appStr];

NSRangerange = [app rangeOfString:@"你要查询App的bundle ID"];

if(range.length >1) 

{    NSLog(@"已安装"); 

 }

}

iOS11 通过私有类 MCMAppContainer 的方式,判断bundID是否安装

代码如下 :

NSBundle*container = [NSBundlebundleWithPath:@"/System/Library/PrivateFrameworks/MobileContainerManager.framework"];

if([container load]) 

{  Class appContainer =NSClassFromString(@"MCMAppContainer");

Bool test = [appContainer performSelector:@selector(containerWithIdentifier:error:) withObject:bundleId withObject:nil];

if(test) 

{returnYES; }

else{returnNO;  }

 }

 到了iOS12,以上方式由于权限问题也被禁了。那有什么其他的方法可以进行判断么?iOS12 只能通过特殊的方法获取是否安装 。目前能做到90%大厂的APP和游戏能检测成功。个别应用还是无法检测到。代码如下:

id space = [NSClassFromString(@"LSApplicationWorkspace") performSelector:@selector(defaultWorkspace)];

    NSArray *plugins = [space performSelector:@selector(installedPlugins)];

    NSMutableSet *list = [[NSMutableSet alloc] init];

    for (id plugin in plugins) {

        id bundle = [plugin performSelector:@selector(containingBundle)];

        if (bundle)

            [list addObject:bundle];

    }


    for (id plugin in list) {

        NSLog(@"%@", [plugin performSelector:@selector(applicationIdentifier)]);

    }

那么到了iOS13 ,还有什么方法呢?云计算,大数据,帮你解决。

你可能感兴趣的:(iOS13 中判断应用是否安装)