获取IOS应用安装列表

news/2024/10/22 14:29:09/

1.openURL
我们知道可以给应用设置URL Scheme,这样别的应用就可以通过这个地址打开咱们的应用。其实还有一个api叫canOpenURL.这样如果咱们知道要检查的IOS应用列表的URL Scheme的话,就可以用canOpenURL检查一下。
2.获取运行程序列表

// .h

@interface UIDevice (ProcessesAdditions)
- (NSArray *)runningProcesses;
@end

// .m
#import <sys/sysctl.h>

@implementation UIDevice (ProcessesAdditions)

- (NSArray *)runningProcesses {

        int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0};
        size_t miblen = 4;
        
        size_t size;
        int st = sysctl(mib, miblen, NULL, &size, NULL, 0);
        
        struct kinfo_proc * process = NULL;
        struct kinfo_proc * newprocess = NULL;
        
    do {
                
        size += size / 10;
        newprocess = realloc(process, size);
                
        if (!newprocess){
                        
            if (process){
                free(process);
            }
                        
            return nil;
        }
                
        process = newprocess;
        st = sysctl(mib, miblen, process, &size, NULL, 0);
                
    } while (st == -1 && errno == ENOMEM);
        
        if (st == 0){
                
                if (size % sizeof(struct kinfo_proc) == 0){
                        int nprocess = size / sizeof(struct kinfo_proc);
                
                        if (nprocess){
                        
                                NSMutableArray * array = [[NSMutableArray alloc] init];
        
                                for (int i = nprocess - 1; i >= 0; i--){
                
                                        NSString * processID = [[NSString alloc] initWithFormat:@"%d", process[i].kp_proc.p_pid];
                                        NSString * processName = [[NSString alloc] initWithFormat:@"%s", process[i].kp_proc.p_comm];
                
                                        NSDictionary * dict = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:processID, processName, nil] 
                                                                                                                                                forKeys:[NSArray arrayWithObjects:@"ProcessID", @"ProcessName", nil]];
                                        [processID release];
                                        [processName release];
                                        [array addObject:dict];
                                        [dict release];
                                }
        
                                free(process);
                                return [array autorelease];
                        }
                }
        }
        
        return nil;
}

@end

// Example usage.
NSArray * processes = [[UIDevice currentDevice] runningProcesses];
for (NSDictionary * dict in processes){
        NSLog(@"%@ - %@", [dict objectForKey:@"ProcessID"], [dict objectForKey:@"ProcessName"]);
}

这种方法是获取运行中的应用列表。如果应用没被运行过或不在后台,就得不到喽。

比起上面两个方法要靠谱一点儿的就是私有API了。

BOOL APCheckIfAppInstalled(NSString *bundleIdentifier){
  static NSString *const cacheFileName = @"com.apple.mobile.installation.plist";
  NSString *relativeCachePath = [[@"Library" stringByAppendingPathComponent: @"Caches"] stringByAppendingPathComponent: cacheFileName];
  NSDictionary *cacheDict = nil;
  NSString *path = nil;
  NSLog(@"relativeCachePath:%@",relativeCachePath);
  // Loop through all possible paths the cache could be in
  for (short i = 0; 1; i++)    {
    switch (i) {
      case 0: // Jailbroken apps will find the cache here; their home directory is /var/mobile
        path = [NSHomeDirectory() stringByAppendingPathComponent: relativeCachePath];
        break;
      case 1: // App Store apps and Simulator will find the cache here; home (/var/mobile/) is 2 directories above sandbox folder
        path = [[NSHomeDirectory() stringByAppendingPathComponent: @"../.."] stringByAppendingPathComponent: relativeCachePath];
        break;
      case 2: // If the app is anywhere else, default to hardcoded /var/mobile/
        path = [@"/var/mobile" stringByAppendingPathComponent: relativeCachePath];
        break;
      default: // Cache not found (loop not broken)
        return NO;
        break; 
    }
    BOOL isDir = NO;
    NSLog(@"path:%@",path);
    // Ensure that file exists
    if ([[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDir] && !isDir){
      cacheDict = [NSDictionary dictionaryWithContentsOfFile: path];
    } 
    
    // If cache is loaded, then break the loop. If the loop is not "broken," it will return NO later (default: case)
    if (cacheDict){
      NSLog(@"cacheDict:%@",cacheDict);
      break;
    } 
    
  }
  
  NSLog(@"gggg");
  // First check all system (jailbroken) apps
  NSDictionary *system = [cacheDict objectForKey: @"System"]; 
  NSLog(@"system:%@",system);
  if ([system objectForKey: bundleIdentifier]){
    return YES;
  }
  
  // Then all the user (App Store /var/mobile/Applications) apps
  NSDictionary *user = [cacheDict objectForKey: @"User"]; 
  NSLog(@"user:%@",user);
  if ([user objectForKey: bundleIdentifier]){
    return YES;
  }
  
  // If nothing returned YES already, we'll return NO now
  return NO;
}

代码方式

还有另外一种获取app列表的方法,代码在 https://github.com/danielamitay/iHasApp

它是利用application的openurl函数,遍历一个5000个app id列表,一个一个在你的iphone上尝试打开这些app,这种实现方式会很快把你的iphone变成暖手宝,只能当个joke。

原文: 点击打开链接

不过这种方法需要机器已经越狱,还需要你的应用不在沙盒里,由于后一条笔者还不大会搞,所以没试成功:)


http://www.ppmy.cn/news/729449.html

相关文章

安全测试(六)iOS ipa软件安全 APP应用安全 手机软件安全 ipa安全 ipa反编译 应用日志窃取 ipa漏洞 应用软件本身功能漏洞 iPhone移动应用常规安全讲解

目录 一、前言 二、iOS ipa软件安全 1、ipa 简介 2、ipa 提取 2.1 工具提取 失败案例 2.2 转包软件提取 失败案例 2.3 日志分析捕获 失败案例 2.4 内测二维码分享 成功案例 3、ipa Info.plist 配置文件分析 4、ipa日志分析 4.1 Windows下爱思助手 4.2 Windows下开源工具 …

iPhone丢了怎么找回

今天无意之间上网冲浪的时候&#xff0c;无意看到iCloud云的强大功能&#xff0c;想到了iPhone中的Find My iPhone功能。 熟悉使用苹果iPhone手机或者iPad设备的朋友&#xff0c;相信对IOS系统里的Find My iPhone 功能比较了解吧。Find My iPhone能够帮我们找回丢失/被盗的iPh…

软件创富密码:iPhone应用程序开发攻略之iPhone特色传感器应用(双色)

软件创富密码&#xff1a;iPhone应用程序开发攻略之iPhone特色传感器应用(双色) 王志刚等 编著 ISBN978-7-121-14440-0 2011年9月出版 定价&#xff1a;69.00元 16开 288页 内 容 简 介 本书集中介绍了如何使用iPhone SDK提供的传感器API开发特色传感器应用程序&…

android 换到iphone,从安卓换到苹果到底是什么感受?最后一个让我彻底放弃了iPhone!...

原标题&#xff1a;从安卓换到苹果到底是什么感受&#xff1f;最后一个让我彻底放弃了iPhone&#xff01; iPhone X是近几年来苹果最具创新力的iPhone&#xff0c;然而高昂的售价让很多消费者望而却步。随着今年苹果秋季新品发布会的临近&#xff0c;苹果即将发布价格更低廉&am…

iphone android 功能清单,iPhone的这几个App,让你的工作效率翻倍(1)

要论哪款手机在职场人士中最受欢迎&#xff0c;那么iPhone肯定是其中之一。可惜的是&#xff0c;很多人使用iPhone&#xff0c;主要还是用来通话&#xff0c;发短信&#xff0c;发微信。其实&#xff0c;iPhone最大的好处&#xff0c;是可以用来提升我们的工作效率&#xff0c;…

亲子拍拍v1.2.1官方iPhone版

亲子拍拍v1.2.1官方iPhone版 版本&#xff1a;1.2.1 大小&#xff1a;12.6MB软件语言&#xff1a;简体中文 软件类型&#xff1a;拍照美图软件授权&#xff1a;免费版 系统要求&#xff1a;iOS6.0 软件简介 亲子拍拍app这是一款亲子应用&#xff0c;家长们可以用这款亲子拍拍…

文件宝iOS/iPhone/iPad客户端简介

App Store地址&#xff1a;https://itunes.apple.com/cn/app/id1023365565?mt8文件宝-装机必备的文件管家&#xff0c;专业的rar-zip 解压工具&#xff0c;局域网看片神器&#xff0c;不用下载&#xff0c;直接播放电脑里的小电影。除此此外&#xff0c;它还是一款精美且专业的…

为iphone12而生 南卡无线磁吸快充充电宝

▼前言 随着时代发展和科技进步&#xff0c;手机及相关数码行业发展愈发加快&#xff0c;产品更迭速度可谓是以日计算&#xff0c;新品发售或新专利发布速度之快&#xff0c;让人感到目不暇接。用户对产品性能和使用体验追求越来越高&#xff0c;厂商迎合用户将手机性能提升的…