相关疑难解决方法(0)

检查应用程序范围书签下的路径是否可在沙盒应用程序内写入

我有一个OS X应用程序,它存储应用程序范围的书签以持久访问某些目录.我能够毫无问题地写入这些目录,但是我的代码中有一部分我要进行额外的检查以确认路径是可写的并且失败了.

var fileManager: NSFileManager = NSFileManager.defaultManager()
var baseUrl: NSURL = try! NSURL(byResolvingBookmarkData: data, …)
var fileUrl: NSURL = url.URLByAppendingPathComponent("foo.txt")

// Changing this order has no effect, I make only the first start access call,
// the second one is to demonstrate that it's not working.

baseUrl.startAccessingSecurityScopedResource() // true
fileUrl.startAccessingSecurityScopedResource() // false

// File manager confirms that base path is writable, but anything inside
// it – not. This worked perfectly fine before sandboxing the app.

fileManager.isWritableFileAtPath(baseUrl.path!) // true
fileManager.isWritableFileAtPath(fileUrl.path!) …
Run Code Online (Sandbox Code Playgroud)

security sandbox objective-c appstore-sandbox swift

5
推荐指数
0
解决办法
218
查看次数

标签 统计

appstore-sandbox ×1

objective-c ×1

sandbox ×1

security ×1

swift ×1