gpt4 book ai didi

objective-c - 应用选择 - Cocoa

转载 作者:搜寻专家 更新时间:2023-10-30 20:11:39 25 4
gpt4 key购买 nike

我想显示一个对话框,允许用户浏览他们当前的应用程序 (/Applications),我需要获取该应用程序的完整路径(已选择)。我该怎么做?感谢代码示例。

谢谢。

最佳答案

这样的事情将是一个好的开始:

NSArray *appsDirs = NSSearchPathForDirectoriesInDomains(NSApplicationDirectory, 
NSLocalDomainMask, YES);
NSString *appsDir = nil;
if ([appsDirs count]) appsDir = [appsDirs objectAtIndex:0];

NSOpenPanel *openPanel = [NSOpenPanel openPanel];
[openPanel setTitle:NSLocalizedString(@"Add Application", @"")];
[openPanel setMessage:NSLocalizedString(@"Choose the application to add.", @"")];
[openPanel setPrompt:NSLocalizedString(@"Add Application", @"")];
[openPanel setAllowsMultipleSelection:YES]; // ?
[openPanel setCanChooseDirectories:NO];
[openPanel setDelegate:self];

NSInteger result = [openPanel runModalForDirectory:appsDir
file:nil
types:
[NSArray arrayWithObject:NSFileTypeForHFSTypeCode('APPL')]];

if (result == NSOKButton) {
NSArray *fileURLs = [openPanel URLs];
for (NSURL *URL in fileURLs) {
NSString *path = [URL path];
// add path, etc.
}
}

关于objective-c - 应用选择 - Cocoa,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6654550/

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