注 :アプリケーションは、任意の Apple デバイスでサンドボックス化され、そのサンドボックス化された環境内でのみ情報を使用できます。ジェイルブレイクされていないデバイスでは、アプリケーション環境外で他のアプリケーションの情報を使用することはできません。非ジェイルブレイクされたデバイスに対して以下のコードを使用しようとすると、Apple はアプリを拒否します。このコードは、ジェイルブレイクされたデバイスにのみ使用してください。
サンプルコード:
-(NSMutableArray *)desktopAppsFromDictionary:(NSDictionary *)dictionary
{
NSMutableArray *desktopApps = [NSMutableArray array];
for (NSString *appKey in dictionary) {
[desktopApps addObject:appKey];
}
return desktopApps;
}
-(void)installedApp
{
static NSString* const installedAppListPath = @"/private/var/mobile/Library/Caches/com.apple.mobile.installation.plist";
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]];
NSLog(@"installedApp :: %@",installedApp);
}
else
{
NSLog(@"Error..");
}
}
功績はIgor Fedorchukにあります。
AppListというライブラリも 1 つあります。ジェイルブレイクされたデバイスで使用できます。