美文网首页
IOS检测APP是否安装(插件法)

IOS检测APP是否安装(插件法)

作者: 刃之剑 | 来源:发表于2021-03-17 08:40 被阅读0次

(通过获取应用的bundleID已经证明不行就不说了)
在iOS 12,以上11,10不同系统的方法是不一样的.
方法:

  • (BOOL) verifyAppWithBundle:(NSString *)bundleID{
    __block BOOL isInstall = NO;

    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
             
                  DLOG(@"installedPlugins:%@",plugins);
         
                  [plugins enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                  NSString *pluginID = [obj performSelector:(@selector(pluginIdentifier))];
                      NSLog(@"pluginID:%@",pluginID);
                      if([pluginID containsString:bundleID]){
                          isInstall = YES;
                          return;
                      }
             }];
    
             return isInstall;
    
         }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) {
                            return YES;
                        } else {
                            return NO;
                          }
    
                  }else{
                      return 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;
             }
         }
         return NO;
    
     }
    

    return NO;

}

问题一:
如何判断自己应用的插件(自己先开发一个就行很好开发的)
问题二:
私有Api能否上架,可以通过热更新的方式下发,或者通过混淆处理.(热更好了)

相关文章

网友评论

      本文标题:IOS检测APP是否安装(插件法)

      本文链接:https://www.haomeiwen.com/subject/wdrscltx.html