2011-08-29 76 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,所以也許甚至可以事先過濾列表。

相關問題