【发布时间】:2014-03-19 14:20:06
【问题描述】:
我正在创建一个应用程序,它收集 OS X 中已安装应用程序的信息。
我试图找到应用程序文件夹中安装的所有应用程序,扩展名为".app"
我创建了一个函数,它可以获取已安装应用程序的一些信息,但我正在寻找更多数据,例如版本、捆绑包 ID 和其他有用信息。
这是我获取属性的方法:
- (NSDictionary *) attributesForFile:(NSURL *)anURI fileName
:(NSString*)fileName{
// note: singleton is not thread-safe
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *aPath = [anURI path];
if (![fileManager fileExistsAtPath:aPath]) return nil;
NSError *attributesRetrievalError = nil;
NSDictionary *attributes = [fileManager attributesOfItemAtPath:aPath
error:&attributesRetrievalError];
if (!attributes) {
NSLog(@"Error for file at %@: %@", aPath, attributesRetrievalError);
return nil;
}
NSMutableDictionary *returnedDictionary =
[NSMutableDictionary dictionaryWithObjectsAndKeys:
[attributes fileType], @"fileType",
[attributes fileModificationDate], @"fileModificationDate",
[attributes fileCreationDate], @"fileCreationDate",
[attributes fileOwnerAccountName],@"fileOwnerAccount",
fileName,@"fileName",
[NSNumber numberWithUnsignedLongLong:[attributes fileSize]], @"fileSize",
nil];
return returnedDictionary;
}
【问题讨论】:
标签: macos cocoa nsfilemanager .app