Iphone 如何在UITableView中列出已安装的应用程序?
我正在尝试获取iPhone(越狱)上所有已安装应用程序的列表,然后在UITableView中列出它们的图标。。。可能吗?谢谢这是可能的,看看我的3G就知道了。不过,我不知道怎么做。它们是检查应用程序是否已安装的一种方法。有时,您可能需要检查设备上是否安装了特定的应用程序,以防您使用需要安装其他应用程序的自定义URL方案(然后您可以灰显/禁用某些按钮)。不幸的是,苹果显然没有任何功能来为您检查这一点,所以我制作了一个。它不会枚举每个应用程序,而是使用MobileInstallation缓存,该缓存始终与SpringBoard保持最新,并保存所有已安装应用程序的信息字典。虽然你不“应该”访问缓存,但它可以读取我的应用商店应用程序。以下是我的代码,它至少在模拟器上运行得非常好:Iphone 如何在UITableView中列出已安装的应用程序?,iphone,objective-c,xcode,uitableview,jailbreak,Iphone,Objective C,Xcode,Uitableview,Jailbreak,我正在尝试获取iPhone(越狱)上所有已安装应用程序的列表,然后在UITableView中列出它们的图标。。。可能吗?谢谢这是可能的,看看我的3G就知道了。不过,我不知道怎么做。它们是检查应用程序是否已安装的一种方法。有时,您可能需要检查设备上是否安装了特定的应用程序,以防您使用需要安装其他应用程序的自定义URL方案(然后您可以灰显/禁用某些按钮)。不幸的是,苹果显然没有任何功能来为您检查这一点,所以我制作了一个。它不会枚举每个应用程序,而是使用MobileInstallation缓存,该缓存
// Declaration
BOOL APCheckIfAppInstalled(NSString *bundleIdentifier); // Bundle identifier (eg. com.apple.mobilesafari) used to track apps
// Implementation
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;
// 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;
if ([[NSFileManager defaultManager] fileExistsAtPath: path isDirectory: &isDir] && !isDir) // Ensure that file exists
cacheDict = [NSDictionary dictionaryWithContentsOfFile: path];
if (cacheDict) // If cache is loaded, then break the loop. If the loop is not "broken," it will return NO later (default: case)
break;
}
NSDictionary *system = [cacheDict objectForKey: @"System"]; // First check all system (jailbroken) apps
if ([system objectForKey: bundleIdentifier]) return YES;
NSDictionary *user = [cacheDict objectForKey: @"User"]; // Then all the user (App Store /var/mobile/Applications) apps
if ([user objectForKey: bundleIdentifier]) return YES;
// If nothing returned YES already, we'll return NO now
return NO;
}
下面是一个例子,假设您的应用程序名为“yourselfmadeapp”,并且是应用程序商店中的一个应用程序
代码:
日志输出:
代码:
NSString*rootAppPath=@“/应用程序”
NSArray*listApp=[[NSFileManager defaultManager]目录目录路径:rootAppPath错误:nil]
NSLog(@“%@”,listApp)
这是获取所有已安装应用程序,然后使用此数组在tableview中显示的方法之一为什么他们总是删除.proj文件damn@Cykey:您应该将您的评论移动到一个单独的答案并接受它。@SeungUnHam:no.proj文件,因为它不应该用Xcode编译,很可能是用Theos编译的。
NSArray *bundles2Check = [NSArray arrayWithObjects: @"com.apple.mobilesafari", @"com.yourcompany.yourselfmadeapp", @"com.blahblah.nonexistent", nil];
for (NSString *identifier in bundles2Check)
if (APCheckIfAppInstalled(identifier))
NSLog(@"App installed: %@", identifier);
else
NSLog(@"App not installed: %@", identifier);
2009-01-30 12:19:20.250 SomeApp[266:20b] App installed: com.apple.mobilesafari
2009-01-30 12:19:20.254 SomeApp[266:20b] App installed: com.yourcompany.yourselfmadeapp
2009-01-30 12:19:20.260 SomeApp[266:20b] App not installed: com.blahblah.nonexistent