我曾经尝试使用
NSFileManager startDownloadingUbiquitousItemAtURL:error:
来强制下载,但返回了一个错误。(请参见EDIT)我的解决方案是,第一次创建文件,然后我猜它存在并用UIDocument打开。但它可能不存在,或者可能是用户第一次打开应用程序。我无法确定这些事情。我的第一个问题是:如果UIDocument打开文件,那么它意味着在某处找到了文件。如果文件不存在,它将如何使用该文件?
其次,第二个问题是:如果我需要管理多个文件或未知名称的文件的应用程序,如果NSMetadataQuery不起作用,我该如何找到它们。
编辑:如果应该使用
startDownloadingUbiquitousItemAtURL
来开始下载文件,我如何知道文件何时完成下载(也许可以通过通知)?但更重要的是:如果始终说“删除原始名称”,我该如何下载文件? Error Domain=NSPOSIXErrorDomain Code=2 "The operation couldn’t be completed.
No such file or directory" UserInfo=0x166cb0 {
NSDescription=Unable to get real path for Path
'/private/var/mobile/Library/Mobile Documents/teamid~com~team~app/Documents/file.extension'
}