Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 通过PowerBox取消NSOpenPanel中用户选择的符号链接_Objective C_Cocoa_Sandbox_Nsopenpanel - Fatal编程技术网

Objective c 通过PowerBox取消NSOpenPanel中用户选择的符号链接

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

在Cocoa中,即在OSX上,我想取消用户在沙盒环境下在
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的硬链接替换符号链接。它必须是一个符号链接