注意:您的应用程序将在任何 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的库。您可以在越狱设备上使用它。