zoukankan      html  css  js  c++  java
  • iOS11 获取手机已安装应用列表

    在iOS 11 以前我们可以使用LSApplicationWorkspace来获取手机上已安装的应用列表

    iOS 11 上获取所有已安装应用接口被禁,但可以根据BundleId检查App是否存在

    - (BOOL)isInstalled:(NSString *)bundleId {
        NSBundle *container = [NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/MobileContainerManager.framework"];
        if ([container load]) {
            Class appContainer = NSClassFromString(@"MCMAppContainer");
    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Wundeclared-selector"
            id container = [appContainer performSelector:@selector(containerWithIdentifier:error:) withObject:bundleId withObject:nil];
    #pragma clang diagnostic pop
            NSLog(@"%@", [container performSelector:@selector(identifier)]);
            if (container) {
                return YES;
            } else {
                return NO;
            }
        }
        return NO;
    }

    此方法在iOS8中不起作用,经笔者验证,此方法在iOS9以上系统可正确运行。

    老方法LSApplicationWorkspace,经笔者验证在iOS8 ~ iOS10均可正常获取所有已安应用

    附老方法代码

    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
        Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
        SEL selector    =   NSSelectorFromString(@"defaultWorkspace");
        NSObject* workspace = [LSApplicationWorkspace_class performSelector:selector];
        SEL selectorALL = NSSelectorFromString(@"allInstalledApplications");
    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Wundeclared-selector"
        NSArray *allInstallApps = [workspace performSelector:selectorALL];
        
        for (NSObject *obj in allInstallApps) {
            NSString *appBundleId   = [obj performSelector:@selector(applicationIdentifier)];
            NSLog(@"installed %@", appBundleId);
        }
    #pragma clang diagnostic pop    // -Wundeclared-selector
    #pragma clang diagnostic pop    // -Warc-performSelector-leaks

    更多私有API探索,感兴趣的同学可用此工具浏览,不幸的是貌似在iOS11上不能完美运行

  • 相关阅读:
    理解缓慢变化维(Slowly Changing Dimension)
    分析Reporting Service的报表执行记录
    XCOPY
    Esxi主机从VC断开的怪事
    奇怪的SQLserver执行
    明细表达到15亿了
    现在才知道“quota”
    oledb读取Excel数据丢失原因
    配置subversion
    sql服务器的操作系统升级,数据库如何来迁移呢?
  • 原文地址:https://www.cnblogs.com/ciml/p/9224826.html
Copyright © 2011-2022 走看看