越狱状态下获取设备上已安装的app和icon
来源:互联网 发布:制作贷款app软件 编辑:程序博客网 时间:2024/05/08 01:25
目前获取已安装app的方法主要有以下几种:
1.通过com.apple.mobile.installation.plist文件获取;
2.通过MobileInstallation.framework获取;
3.通过LSApplicationWorkspace:
#include <objc/runtime.h>Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");NSObject* workspace = [LSApplicationWorkspace_class performSelector:@selector(defaultWorkspace)];NSLog(@"apps: %@", [workspace performSelector:@selector(allApplications)]);
这种方法可以在非越狱情况下使用,但只能获取应用的bundle ID,无法获取中文名称和icon。
我采用的则是最暴力最直接的方法:递归遍历Applications路径下所有app的plist:
- (void)scanApps{ NSString *pathOfApplications; if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) pathOfApplications = @"/var/mobile/Containers/Bundle/Application"; else pathOfApplications = @"/var/mobile/Applications"; NSLog(@"scan begin"); // all applications NSArray *arrayOfApplications = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:pathOfApplications error:nil]; for (NSString *applicationDir in arrayOfApplications) { // path of an application NSString *pathOfApplication = [pathOfApplications stringByAppendingPathComponent:applicationDir]; NSArray *arrayOfSubApplication = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:pathOfApplication error:nil]; // seek for *.app for (NSString *applicationSubDir in arrayOfSubApplication) { if ([applicationSubDir hasSuffix:@".app"]) {// *.app NSString *path = [pathOfApplication stringByAppendingPathComponent:applicationSubDir]; NSString *imagePath = [pathOfApplication stringByAppendingPathComponent:applicationSubDir]; path = [path stringByAppendingPathComponent:@"Info.plist"]; // so you get the Info.plist in the dict NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path]; if([[dict allKeys] containsObject:@"CFBundleIdentifier"] && [[dict allKeys] containsObject:@"CFBundleDisplayName"]){ NSArray *values = [dict allValues]; <span style="white-space:pre"></span> NSString *icon; <span style="white-space:pre"></span> for (int i = 0; i < values.count; i++) { <span style="white-space:pre"></span> icon = [self getIcon:[values objectAtIndex:i] withPath:imagePath]; <span style="white-space:pre"></span> if (![icon isEqualToString:@""]) { } <span style="white-space:pre"></span> imagePath = [imagePath stringByAppendingPathComponent:icon]; <span style="white-space:pre"></span> break; <span style="white-space:pre"></span> } <span style="white-space:pre"></span> } } } } }}
- (NSString *)getIcon:(id)value withPath:(NSString *)imagePath{ if([value isKindOfClass:[NSString class]]) { NSRange range = [value rangeOfString:@"png"]; NSRange iconRange = [value rangeOfString:@"icon"]; NSRange IconRange = [value rangeOfString:@"Icon"]; if (range.length > 0){ NSString *path = [imagePath stringByAppendingPathComponent:value]; UIImage *image = [UIImage imageWithContentsOfFile:path]; if (image != nil && image.size.width > 50 && image.size.height > 50) { return value; } } else if(iconRange.length > 0){ NSString *imgUrl = [NSString stringWithFormat:@"%@.png",value]; NSString *path = [imagePath stringByAppendingPathComponent:imgurl]; UIImage *image = [UIImage imageWithContentsOfFile:path]; if (image != nil && image.size.width > 50 && image.size.height > 50) { return imgUrl<span style="font-family: Arial, Helvetica, sans-serif;">;</span> } } else if(IconRange.length > 0){ NSString *imgUrl = [NSString stringWithFormat:@"%@.png",value]; NSString *path = [imagePath stringByAppendingPathComponent:imgurl]; UIImage *image = [UIImage imageWithContentsOfFile:path]; if (image != nil && image.size.width > 50 && image.size.height > 50) { return imgUrl; } } } else if([value isKindOfClass:[NSDictionary class]]){ NSDictionary *dict = (NSDictionary *)value; for (id subValue in [dict allValues]) { NSString *str = [self getIcon:subValue withPath:imagePath]; if (![str isEqualToString:@""]) { return str; } } } else if([value isKindOfClass:[NSArray class]]){ for (id subValue in value) { NSString *str = [self getIcon:subValue withPath:imagePath]; if (![str isEqualToString:@""]) { return str; } } } return @"";}
0 0
- 越狱状态下获取设备上已安装的app和icon
- 越狱状态下获取设备上已安装的app和icon
- ios获取本机已安装的app列表 前提是必须越狱才能获取
- 通过adb和shell 怎样获取Android设备已安装的App
- 如何在越狱设备ROOT权限下安装APP
- iOS获取当前设备上所有安装的App
- android 获取已安装apk的icon和名字以及size
- android 获取已安装apk的icon和名字以及size
- 如何在未越狱的iOS 设备上安装 ipa
- 获取已安装设备的高级信息
- 获取已安装设备的高级信息
- iOS获取app已安装列表和安装app
- 获取已安装APP的信息
- 获取已安装APP的apk文件
- ADB检查APP已安装列,是否已安装,获取已安装APP的版本号,
- 获取已安装应用在/data/app目录下的apk安装包,并分享
- LibAhead for iOS - 在未越狱设备上修改三方APP的功能
- iHasApp----如何获取本机已安装的程序(未越狱一)
- linux kernel内核编程基础总结
- 【译】依赖注入:代码的一针强心剂
- Android Bitmap 全面解析
- socket编程实现的多人局域网聊天(udp)多线程
- 简单的nodejs 文件系统(fs)读写
- 越狱状态下获取设备上已安装的app和icon
- Code Forces 584 C. Marina and Vasya(水~)
- 学习HTML:iframe用法总结收藏
- MSSQL中整理索引碎片的存储过程
- JavaSE8-The New Date and Time API(2)
- 接龙游戏
- git stash
- SRM 669 DIV 2 CombiningSlimes 500-point
- Android新增一个emmc 上层的实现