我正在创建一个应用程序,该应用程序收集OS X中已安装的应用程序的信息。
我试图找到".app"
扩展名为Applications文件夹中安装的所有应用程序
我创建了一个函数,该函数可以为我提供已安装应用程序的一些信息,但是我正在寻找更多数据,例如版本,捆绑软件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;
}
为什么要同时传递一个NSURL
参数和一个参数NSString
?
您可以从NSBundle
该应用程序的中获取所需的信息:
NSBundle *myBundle = [NSBundle bundleWithPath:@"/Applications/SomeApp.app"];
NSLog(@"%@", [myBundle infoDictionary]);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句