iOS12 检测手机中是否安装其他应用

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

 

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值