我有越狱iphone和越狱itouch。我想要的是在设备上列出已安装的应用程序。它在iphone上很成功,但它在itouch中失败了。相同的代码,但结果不同,这让我很烦恼。
NSFileManager* fileManager = [NSFileManager defaultManager];
for (NSString *path in [fileManager contentsOfDirectoryAtPath:@"/var/mobile/Applications" error:NULL])
{
NSError *error;
for (NSString *subPath in [fileManager contentsOfDirectoryAtPath:[NSString stringWithFormat:@"/var/mobile/Applications/%@",path] error:&error])
{
NSLog(@"@\n",subPath);
if ([subPath hasSuffix:@".app"])
{
NSString* infoplist = [NSString stringWithFormat:@"/var/mobile/Applications/%@/%@/Info.plist", path, subPath];
NSDictionary* dict = [NSDictionary dictionaryWithContentsOfFile:infoplist];
if ([dict objectForKey:@"CFBundleDisplayName"])
{
NSString *str = [dict objectForKey:@"CFBundleDisplayName"];
NSLog(@"%@",str);
textView.text = [NSString stringWithFormat:@"%@\n%@",textView.text,str];
}
}
}
NSLog(@"%@",[error description]);