gpt4 book ai didi

ios - 在 iOS 上保存 iCloud Drive 安全范围的 URL (UIDocumentPickerViewController)

转载 作者:可可西里 更新时间:2023-11-01 17:06:28 26 4
gpt4 key购买 nike

我正在尝试保存从 iCloud 文档选择器 (UIDocumentPickerViewController) 返回的安全范围 URL

文档指出:

If the URL is not a ubiquitous URL, save a bookmark to the file using the bookmarkDataWithOptions:includingResourceValuesForKeys:relativeToURL:error: method and passing in the NSURLBookmarkCreationWithSecurityScope option. Calling this method creates a bookmark containing a security-scoped URL that you can use to open the file without further user intervention.

但是,编译器说 NSURLBookmarkCreationWithSecurityScope 在 iOS 上不受支持。

有谁知道这里发生了什么......?

最佳答案

进一步挖掘后,发现在 IOS 中创建书签数据时根本不需要选项 NSURLBookmarkCreationWithSecurityScope。它是 OS X 的一个选项。您可以只为选项字段传递 nil。我认为 Apple 的文档充其量是令人困惑的。
但是,您确实需要在创建书签之前调用 startAccessingSecurityScopedResource 并确保调用在继续之前返回 1(成功)。否则,书签创建将失败。这是示例代码:

 if ([url startAccessingSecurityScopedResource]==1) {  
NSError *error;
NSData *bookmark = [url bookmarkDataWithOptions:nil
includingResourceValuesForKeys:nil
relativeToURL:nil
error:&error];
if (error) {
//handle error condition
} else {
// save your bookmark
}
}
[url stopAccessingSecurityScopedResource];

Apple 的文档充其量只是困惑!我花了很多时间才发现这一点。希望这会有所帮助。

关于ios - 在 iOS 上保存 iCloud Drive 安全范围的 URL (UIDocumentPickerViewController),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27024189/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com