IOS获取手机所有应用的Bundle id
2015-09-07 12:07
459 查看
方法一分享一个开源的dawin文件, 用来获取手机需要的数据存到C的buffer,下面给上需要的darwin文件。文件点这里
把这2个文件放到你的工程里面,然后include“darwin.h”;
使用下面代码用来获取列表信息
现在你有了应用程序的安装位置,打开info.plists那些目录下再使用下面的代码分别获取bundle id
如果不成功的话,你可能需要root权限;
方法二,获取程序所有bundle id还有另外一个方法就是使用命令行ps
-Aef 这可以看到电脑所有的进程,当然手机的话你需要运行ps
-Aef >> /var/mobile/Library/MyAppName/ps.txt" 调用然后把日志文件发送出去。
方法三、使用如下代码获取所有的进程
大概就这些了
把这2个文件放到你的工程里面,然后include“darwin.h”;
使用下面代码用来获取列表信息
char * OS_initialize(){ size_t buffSize = 20000; // you may need to increase this! char buffer[buffSize]; int bytes = OS_get_table(buffer, buffSize); NSString *text; if (bytes > 0) { text = [NSString stringWithCString: buffer encoding: NSASCIIStringEncoding]; NSLog(@"%@",text); } return ""; }
现在你有了应用程序的安装位置,打开info.plists那些目录下再使用下面的代码分别获取bundle id
NSString* filename = @"/var/mobile/Applications/8AA99EA8-9CFC-4237-9BD1-7C2812EDAAD4/Starbucks.app/Info.plist"; NSDictionary* dict = [[NSDictionary alloc] initWithContentsOfFile: filename]; NSString* bundleID = [dict valueForKey: @"CFBundleIdentifier"];
如果不成功的话,你可能需要root权限;
方法二,获取程序所有bundle id还有另外一个方法就是使用命令行ps
-Aef 这可以看到电脑所有的进程,当然手机的话你需要运行ps
-Aef >> /var/mobile/Library/MyAppName/ps.txt" 调用然后把日志文件发送出去。
方法三、使用如下代码获取所有的进程
首先引入头文件#import <sys/sysctl.h>然后使用如下代码
- (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; }
大概就这些了
相关文章推荐
- 详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!【2012-12-11日更新获取"产品付费数量等于0的问题"】
- 仿iOS滚轮时间选择器和地区选择
- 配置描述文件web clip-iOS技巧:不越狱在主屏创建快速拨打图标
- iOS不用调用,running time自动执行方法
- iOS KVC & KVO
- 12.iOS格式化日志输出的方法以及在发布状态自动关闭NSLog方法
- ios NSMutableAttributedString 详解 显示不同的字体和颜色的字符串
- iOS 版本判定
- iOS Wi-Fi 描述文件:关于“自动加入”和单一连接密码设置
- IOS应用程序多语言本地化解决方案
- 《转》nagios 详细的安装及配置!
- iOS开发 iOS8系统新出cell侧滑View
- iOS NSString的长度计算
- IOS彩票第一天基本框架搭建
- IOS ARC项目使用非ARC文件
- IOS中懒加载
- iOS开源库
- iOS学习--NSCalendar
- iOS中3种正则表达式的使用与比较
- IOS中点语法