gpt4 book ai didi

macos - 在 OS X 中查找已安装应用程序的版本

转载 作者:行者123 更新时间:2023-12-03 16:17:19 30 4
gpt4 key购买 nike

我正在创建一个应用程序,用于收集 OS X 中已安装应用程序的信息。

我尝试查找应用程序文件夹中安装的所有带有“.app”扩展名的应用程序

我创建了一个函数,可以获取已安装应用程序的一些信息,但我正在寻找更多数据,例如版本、 bundle 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;
}

最佳答案

  1. 为什么要同时传递 NSURL 参数和 NSString 参数?

  2. 您可以从应用的 NSBundle 获取所需的信息:

    NSBundle *myBundle = [NSBundle bundleWithPath:@"/Applications/SomeApp.app"];
    NSLog(@"%@", [myBundle infoDictionary]);

关于macos - 在 OS X 中查找已安装应用程序的版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21877333/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com