Search code examples
iphoneiosobjective-cipadicloud

startDownloadingUbiquitousItemAtURL local file path?


Where does startDownloadingUbiquitousItemAtURL:error method save downloaded file in local?
Is it the same as given URL?


Solution

  • Yes , its the same URL

    The file in place before it downloads from iCloud to the device is a placeholder of sorts.

    You can check the status of the URL with the key NSURLUbiquitousItemIsDownloadedKey

    NSURL *foo = file://cloud/container/reference/tofile;
    
    NSNumber *isDownloadedValue = NULL;
    
    BOOL success = [foo getResourceValue:&isDownloadedValue forKey: NSURLUbiquitousItemIsDownloadedKey error:NULL];
    
    if (success && ![isDownloadedValue boolValue]) {
        [[NSFileManager defaultManager] startDownloadingUbiquitousItemAtURL:foo error:NULL];
    }
    

    Theres no error handling in that snippet which you will want to do in production code.