【发布时间】:2017-10-25 12:14:24
【问题描述】:
考虑到file access in a sandboxed osx app with swift,它是否与通过 Finder 或其他应用程序提供的 URL 一样工作?
由于没有 NSOpenPanel 调用来提供本示例中的文件夹访问权限,只有 url - 我认为文件夹访问是隐式的,因为用户从源/桌面“文件夹”拖动文件与通过打开的隐式选择大致相同对话框。
我尚未开始沙盒迁移,但想验证我的想法是否准确,但这里有一个候选例程不在沙盒模式下工作:
func performDragOperation(_ sender: NSDraggingInfo!) -> Bool {
let pboard = sender.draggingPasteboard()
let items = pboard.pasteboardItems
if (pboard.types?.contains(NSURLPboardType))! {
for item in items! {
if let urlString = item.string(forType: kUTTypeURL as String) {
self.webViewController.loadURL(text: urlString)
}
else
if let urlString = item.string(forType: kUTTypeFileURL as String/*"public.file-url"*/) {
let fileURL = NSURL.init(string: urlString)?.filePathURL
self.webViewController.loadURL(url: fileURL!)
}
else
{
Swift.print("items has \(item.types)")
}
}
}
else
if (pboard.types?.contains(NSPasteboardURLReadingFileURLsOnlyKey))! {
Swift.print("we have NSPasteboardURLReadingFileURLsOnlyKey")
}
return true
}
因为没有 URL 被执行或抛出错误。
【问题讨论】:
标签: macos swift3 drag-and-drop appstore-sandbox nspasteboard