美文网首页
iOS 获取手机上安装的app

iOS 获取手机上安装的app

作者: 某个胖子 | 来源:发表于2016-03-27 13:48 被阅读1502次

    前段时间,因为项目需求,需要知道目前手机上都安装了哪些app(非系统自带),因此在网上找了找,发现苹果提供的私有api 是具有此功能的。代码如下:
    - (NSArray *)getAllAppsFromDevice
    {
    //获取手机上所有的app
    Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
    NSObject *workspace = [LSApplicationWorkspace_class performSelector:@selector(defaultWorkspace)];
    NSArray *apps = [workspace performSelector:@selector(allInstalledApplications)];
    Class LSApplicationProxy_class = objc_getClass("LSApplicationProxy");
    NSMutableArray *deviceApps = [NSMutableArray new];
    for (int i = 0; i < apps.count; i++) {
    NSObject *temp = apps[i];
    if ([temp isKindOfClass:LSApplicationProxy_class]) {
    ApplicationModel *appModel = [[ApplicationModel alloc] init];
    NSString *tempKey = [temp performSelector:NSSelectorFromString(@"applicationIdentifier")];
    if ([tempKey containsOtherString:@"apple"]) {
    continue;
    }
    //版本
    NSString *tempVersionNumber = [temp performSelector:NSSelectorFromString(@"shortVersionString")];
    appModel.appNumber = tempVersionNumber;

         //bundle id
         NSString *tempAppkey = [temp performSelector:NSSelectorFromString(@"applicationIdentifier")];
         appModel.appKey = tempAppkey;
         [deviceApps addObject:appModel];
          }
       }
       return [deviceApps copy];
    }

    相关文章

      网友评论

          本文标题:iOS 获取手机上安装的app

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