重用安全范围书签

重用安全范围书签,第1张

重用安全范围书签

我用 NSUserDefaults 弄清楚了。

var userDefault = NSUserDefaults.standardUserDefaults()var folderPath: NSURL? {    didSet {        do { let bookmark = try folderPath?.bookmarkDataWithOptions(.SecurityScopeAllowOnlyReadAccess, includingResourcevaluesForKeys: nil, relativeToURL: nil) userDefault.setObject(bookmark, forKey: "bookmark")        } catch let error as NSError { print("Set Bookmark Fails: (error.description)")        }    }}func applicationDidFinishLaunching(aNotification: NSNotification) {    if let bookmarkData = userDefault.objectForKey("bookmark") as? NSData {        do { let url = try NSURL.init(byResolvingBookmarkdata: bookmarkData, options: .WithoutUI, relativeToURL: nil, bookmarkDataIsStale: nil) url.startAccessingSecurityScopedResource()        } catch let error as NSError { print("Bookmark Access Fails: (error.description)")        }    }}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4957140.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-13
下一篇 2022-11-13

发表评论

登录后才能评论

评论列表(0条)

保存