ios - How to copy file in iCloud to app sandbox using File Manager -
i have file in cloud 15.2 kb. cannot copy app sandbox. code listed below. appreciated
nsurl *ubiq = [[nsfilemanager defaultmanager] urlforubiquitycontaineridentifier:nil]; if (ubiq) { nserror *error = nil; nsfilemanager *filemanager = [nsfilemanager defaultmanager]; nsurl *cloudcontainerurl = [filemanager urlforubiquitycontaineridentifier:nil]: nsurl*dirurl=[cloudcontainerurl urlbyappendingpathcomponent:@"documents" isdirectory:yes]; [filemanager createdirectoryaturl:dirurl withintermediatedirectories:no attributes:nil error:&error]; nsurl *icloudurl = [dirurl urlbyappendingpathcomponent:@"passwords file.txt"]; nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentspath = [paths objectatindex:0]; // destination path nsstring *fileindocumentspath = [documentspath stringbyappendingpathcomponent:@"passwords file.txt"]; nsurl* sandboxdocumenturl = [nsurl fileurlwithpath:fileindocumentspath]; [[ nsfilemanager defaultmanager ] copyitematurl:icloudurl tourl:sandboxdocumenturl error:&error ];
you can't copy file icloud local directory, because file might not exist on local device yet. app's icloud files downloaded on demand, , haven't done create demand. result, there's no source file copy. if know file in cloud, can't access until exists locally.
if checking error
parameter passed copyitematurl:tourl:error:
might know this.
to download file use -[nsfilemanager startdownloadingubiquitousitematurl:error:]
. begins process. can find out when download finishes using 1 of:
nsmetadataquery
, post update when download finishes, ornsfilemanager
, won't notify havensurlubiquitousitemisdownloadedkey
flag can check.
Comments
Post a Comment