2011-08-29 98 views
24

我想获得所有安装的应用程序(NSArray)的列表。我的应用程序是越狱应用程序,位于/ Applications,因此Sandbox在那里没有问题。有什么办法可以获得应用商店应用列表吗?我已经在其他应用程序(Activator,SBSettings ...)中看到了这一点。我不知道如何做到这一点,因为所有的应用程序沙箱都有这么大的代码,所以我不知道如何才能访问沙箱内的.app文件夹。获取所有安装的应用程序的列表

回答

13

您可以使用此代码片段:

#import "InstalledAppReader.h" 

static NSString* const installedAppListPath = @"/private/var/mobile/Library/Caches/com.apple.mobile.installation.plist"; 

@interface InstalledAppReader() 

-(NSArray *)installedApp; 
-(NSMutableDictionary *)appDescriptionFromDictionary:(NSDictionary *)dictionary; 

@end 


@implementation InstalledAppReader 

#pragma mark - Init 
-(NSMutableArray *)desktopAppsFromDictionary:(NSDictionary *)dictionary 
{ 
    NSMutableArray *desktopApps = [NSMutableArray array]; 

    for (NSString *appKey in dictionary) 
    { 
     [desktopApps addObject:appKey]; 
    } 
    return desktopApps; 
} 

-(NSArray *)installedApp 
{  
    BOOL isDir = NO; 
    if([[NSFileManager defaultManager] fileExistsAtPath: installedAppListPath isDirectory: &isDir] && !isDir) 
    { 
     NSMutableDictionary *cacheDict = [NSDictionary dictionaryWithContentsOfFile: installedAppListPath]; 
     NSDictionary *system = [cacheDict objectForKey: @"System"]; 
     NSMutableArray *installedApp = [NSMutableArray arrayWithArray:[self desktopAppsFromDictionary:system]]; 

     NSDictionary *user = [cacheDict objectForKey: @"User"]; 
     [installedApp addObjectsFromArray:[self desktopAppsFromDictionary:user]]; 

     return installedApp; 
    } 

    DLOG(@"can not find installed app plist"); 
    return nil; 
} 

@end 
+0

这是不是一个私人API? – iJatrat

+5

这不是一个私人API,但我们可以访问私人文件夹。 Apple会拒绝你的应用程序。仅对越狱iPhone使用此代码。 – Igor

+2

@Fedorchuk,我怎么能从普通的iOS设备得到这个安装的应用程序列表,我的意思是没有越狱iPhone,plz帮助我做到这一点。没有越狱iPhone的 – maddysan

6

在越狱的iPhone上,您只需阅读/Applications文件夹即可。所有安装的应用程序都会去只需使用NSFileManager列出的目录中/Applications

NSArray *appFolderContents = [[NSFileManager defaultManager] directoryContentsAtPath:@"/Applications"]; 
+1

只读预安装的应用程序和cydia应用程序,即时通讯讨论应用程序商店应用程序。 – JonasG

+1

尝试移动用户的应用程序文件夹:'/ private/var/mobile/Applications' –

+0

@BjörnMarschollek:非常感谢。我帮了我很多。 – Pushkraj

2

另外还有AppList library,这将做所有的脏活的你: rpetrich/AppList 它在很多越狱调整中使用,所以我不知道为什么它没有建议在这里。

获取AppStore应用程序的一种方法是检查列表中返回的每个应用程序的值为isSystemApplication。那些值设为NO的是常规的AppStore应用程序。还有一个功能applicationsFilteredUsingPredicate:predicate,所以也许甚至可以事先过滤列表。

相关问题