我尝试使用objective-c在Mac App中打开文件夹"~/Library/Application Support/Mozilla"
。
NSString *stringContaingPath = @"~/Library/Application Support/Mozilla";
NSURL *folderURL = [NSURL fileURLWithPath:stringContaingPath];
[[NSWorkspace sharedWorkspace] openURL: folderURL];
但每次我收到错误
当我去打开它时。
虽然文件夹确实存在。
打开文件夹需要做些什么吗?我没有尝试写信,只是打开它让用户看。
答案 0 :(得分:1)
~
符号仅对shell有意义。您必须使用NSHomeDirectory()
将其展开为/Users/username
;即:
NSString *pathName = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/Mozilla"];
但是,这仅适用于非沙盒应用。