我已打开App沙盒并勾选USB访问和用户选定文件(只读)。
当我尝试以模态方式打开NSOpenPanel时,它会打开
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
NSArray* fileTypes = [[NSArray alloc] initWithObjects:@"txt", nil];
[openPanel setAllowsMultipleSelection: NO];
[openPanel setCanChooseDirectories:NO];
[openPanel setCanCreateDirectories:NO];
[openPanel setCanChooseFiles:YES];
[openPanel setAllowedFileTypes:fileTypes];
[openPanel setDirectoryURL:[self getFileURL]];
[openPanel beginWithCompletionHandler:^(NSInteger result){
if (result == NSFileHandlingPanelOKButton) {
NSURL* selectedFileUrl = [[openPanel URLs] objectAtIndex:0];
}
}];
这是以表格形式打开的代码:
[openPanel beginSheetModalForWindow:[NSApp mainWindow] completionHandler:^(NSInteger result){
if (result == NSFileHandlingPanelOKButton) {
NSURL* selectedFileUrl = [[openPanel URLs] objectAtIndex:0];
}
}];
执行上述代码时没有任何反应。
NSURL是:file:///Volumes/SE23/documents/My%.File.txt