获取IOS应用安装列表
原文转载至 http://blog.csdn.net/justinjing0612/article/details/8887747
转自鸟哥博客:http://blog.cnrainbird.com/index.php/2012/04/19/guan_yu_huo_qu_ios_ying_yong_lie_biao/?utm_source=rss
当两天没事儿,突然想起这么一个命题:获取IOS应用安装列表。
研究来研究去最后也没有得出个所以然来。这不今天上网,发现这篇儿文章。晾这说有三种方法。也就顺便总结一下,边转载边补充。
ok,说是三种方法,靠谱的两种:
1.openURL
我们知道可以给应用设置URL Scheme,这样别的应用就可以通过这个地址打开咱们的应用。其实还有一个api叫canOpenURL.这样如果咱们知道要检查的IOS应用列表的URL Scheme的话,就可以用canOpenURL检查一下。
2.获取运行程序列表
- </pre><pre name="code" class="html">// .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;
- }
不过这种方法需要机器已经越狱,还需要你的应用不在沙盒里,由于后一条笔者还不大会搞,所以没试成功:)
获取IOS应用安装列表的更多相关文章
- iOS学习——获取iOS设备的各种信息
不管是在Android开发还是iOS开发过程中,有时候我们需要经常根据设备的一些状态或信息进行不同的设置和性能配置,例如横竖屏切换时,电池电量低时,内存不够时,网络切换时等等,我们在这时候需要进行一些 ...
- iOS11 获取手机已安装应用列表
在iOS 11 以前我们可以使用LSApplicationWorkspace来获取手机上已安装的应用列表 iOS 11 上获取所有已安装应用接口被禁,但可以根据BundleId检查App是否存在 - ...
- python获取软件安装列表2222
softer_installed_list ===================== 使用python编写的,获取本机软件安装列表,输出为html表格. * win7 32位环境下运行 * 使用的是 ...
- 利用RxJava获取手机已安装的App的图片、应用名称和版本号
先上效果图: 获取手机已安装的App列表利用Android系统API就可以办到,这里为什么要引入RxJava?现在我们假设一下有下面几个需求: 1.我们不需要所有的App,只需要用户安装的第三方App ...
- 怎么获取iOS的私有API
前言 作为iOS开发人员,相信大多数伙伴都对怎么获取iOS的私有API很有兴趣,最近通过查找资料,总结了以下三种方法,希望对你有用. 第一种(class-dump) 不得不说这是一个很棒的工具,安装和 ...
- iOS TableView多级列表
代码地址如下:http://www.demodashi.com/demo/15006.html 效果预览 ### 一.需求 TableView多级列表:分级展开或合并,逐级获取并展示其子级数据,可以设 ...
- iOS系统声音列表
iOS系统声音列表 效果 说明 1. 点击cell就能发出声音 2. 只需要给出声音编号,就可以,非常简单易用 源码 https://github.com/YouXianMing/iOS-Utilit ...
- 获取ios设备的udid
今天get的第二个技能~~~ UDID指的是设备的唯一设备识别符,ipa包未上架之前如果不添加udid是无法安装成功的.那么如何快速获取ios设备的udid呢? 今天get的方法是用蒲公英,网址:ht ...
- Unity3D开发之“获取IOS设备所在的国家代码"
原地址:http://dong2008hong.blog.163.com/blog/static/469688272014021025578/ 在前一段时间游戏开发中需要实现获取IOS设备所在的国家代 ...
随机推荐
- iOS NSLog各种打印
%@ 对象 %d,%i 整型 (%i的老写法) %hd 短整型 %ld , %lld 长整型 %u 无符整型 %f 浮点型和double型 %0.2f 精度浮点数,只保留两位小数 %x: 为32 ...
- BZOJ2425 [HAOI2010]计数 【数位dp】
题目 你有一组非零数字(不一定唯一),你可以在其中插入任意个0,这样就可以产生无限个数.比如说给定{1,2},那么可以生成数字12,21,102,120,201,210,1002,1020,等等. 现 ...
- 刷题总结:最长公共字串(spoj1811)(后缀自动机)
题目: 就不贴了吧···如题: 题解: 后缀自动机模版题:没啥好说的···· 代码: #include<iostream> #include<cstdio> #include& ...
- 算法复习——splay+启发式合并(bzoj2733-永无乡)
题目: Description 永无乡包含 n 座岛,编号从 1 到 n,每座岛都有自己的独一无二的重要度,按照重要度可 以将这 n 座岛排名,名次用 1 到 n 来表示.某些岛之间由巨大的桥连接,通 ...
- centos7如何查看ip信息(centos 6.5以前都可以用ifconfig 但是centos 7里面没有了,centos 7用什么查看?)
展开全部 centos7如何查看ip信息可以这样解决: 1.首先要先查看一下虚拟机的ip地址,因为ipconfig不是centos7,因此要使用 ip addr来查看. 2.查看之后你就会发现ens3 ...
- CatchTheCaw ----广搜入门
抓住那头牛(POJ3278)农夫知道一头牛的位置,想要抓住它.农夫和牛都位于数轴上,农夫起始位于点N(0<=N<=100000),牛位于点K(0<=K<=100000).农夫有 ...
- bigdata related
hive: http://lxw1234.com/archives/2015/07/413.htm 搜狗实验室数据集: https://www.sogou.com/labs/resource/list ...
- 标准C程序设计七---10
Linux应用 编程深入 语言编程 标准C程序设计七---经典C11程序设计 以下内容为阅读: <标准C程序设计>(第7版) 作者 ...
- Hihocoder 1561 观光旅行(启发式合并+贪心)
题目链接 Hihocoder 1561 首先对原图求$MST$ 我们发现某条边成为某两个点的关键路径的必要条件是这条边是最小生成树的树边. 所以我们求$MST$的同时进行启发式合并. 把$size$小 ...
- MySQL与MSSQL的一些语法差异(持续更新中)
分号不能少:分号不能少:分号不能少:重要的事情说3遍 Insert或者Update的数据包含反斜杠\的时候需要进行转义\\,例:insert into tablename(id,name) value ...