1

你好,我已经上传了一个 sqlite3 文件到 icloud。现在我想将此文件下载到我的 APP 的 Document 文件夹中。我按下下载按钮后,它会显示成功信息。但实际上,documents 文件夹中没有 sqlite 文件,或者文件可能已损坏。有人可以帮助我吗?

-(IBAction)downloadPressed:(id)sender
{
    if(![self downloadFileIfNotAvailable:self.icloudURL])
    {
        [self displayAlert:@"Warning!!" withmessage:@"failed to restore"];
    }else{
        [self displayAlert:@"Congratulations" withmessage:@"restore sccuessfully"];
    }
}

-(BOOL)downloadFileIfNotAvailable:(NSURL *)file
{
    NSNumber*  isIniCloud = nil;
    NSError* err;
    if ([file getResourceValue:&isIniCloud forKey:NSURLIsUbiquitousItemKey error:nil]) {
        // If the item is in iCloud, see if it is downloaded.
        if ([isIniCloud boolValue]) {
            NSFileManager* fm = [NSFileManager defaultManager];
            if([fm removeItemAtPath:self.filePath error:&err])
            {
                if (![fm startDownloadingUbiquitousItemAtURL:file error:nil]) {
                    return NO;
                }else{
                    return YES;
                }
            }
        }
        return NO;
    }
    return NO;
}
4

0 回答 0