Objective c 通过PowerBox取消NSOpenPanel中用户选择的符号链接
在Cocoa中,即在OSX上,我想取消用户在沙盒环境下在Objective c 通过PowerBox取消NSOpenPanel中用户选择的符号链接,objective-c,cocoa,sandbox,nsopenpanel,Objective C,Cocoa,Sandbox,Nsopenpanel,在Cocoa中,即在OSX上,我想取消用户在沙盒环境下在NSOpenPanel中选择的符号链接的链接 我正在编写的代码如下: NSOpenPanel *openPanel = [NSOpenPanel openPanel]; openPanel.resolvesAliases = NO; openPanel.canChooseDirectories = NO; openPanel.allowedFileTypes = @[(NSString *)kUTTypeSymLink]; [openPa
NSOpenPanel
中选择的符号链接的链接
我正在编写的代码如下:
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
openPanel.resolvesAliases = NO;
openPanel.canChooseDirectories = NO;
openPanel.allowedFileTypes = @[(NSString *)kUTTypeSymLink];
[openPanel beginSheetModalForWindow:[[self view] window]
completionHandler:^(NSInteger returnCode)
{
if (returnCode == NSFileHandlingPanelCancelButton) { return; }
int status = unlink(openPanel.URL.fileSystemRepresentation);
if (status < 0) {
NSLog(@" failed unlinking symbolic link at %s", openPanel.URL.fileSystemRepresentation);
}
}];
NSOpenPanel*openPanel=[NSOpenPanel-openPanel];
openPanel.resolvesAliases=否;
openPanel.canChooseDirectories=否;
openPanel.allowedFileTypes=@[(NSString*)kUTTypeSymLink];
[openPanel beginSheetModalForWindow:[[self-view]窗口]
completionHandler:^(NSInteger返回代码)
{
如果(returnCode==NSFileHandlingPanelCancelButton){return;}
int status=unlink(openPanel.URL.fileSystemRepresentation);
如果(状态<0){
NSLog(@“在%s处取消符号链接失败”,openPanel.URL.fileSystemRepresentation);
}
}];
将NO
设置为resolvesAliases
属性效果良好,因此不会解析符号链接。因此,openPanel.URL
返回用户在openPanel中选择的正确位置
但是,unlink
命令失败,状态为-1
,因为PowerBox没有为用户选择的URL处的符号文件授予写入权限
我当然在我的授权文件中添加了com.apple.security.files.user selected.read-write
键YES
。除此之外,我正在使用Xcode 6.4+OSX10.10SDK,并在OSX10.10.5上运行它
如何成功地取消链接用户选择的符号链接?
或者,根本不可能在沙盒环境下取消符号链接吗
[注意]在这种情况下,我不能用OS X的别名或UNIX的硬链接替换符号链接。它必须是一个符号链接