嗨,我已经将一个sqlite3文件上传到了icloud。现在我想将此文件下载到我的APP的Document文件夹中。按下下载按钮后,将显示成功信息。但事实上,文档文件夹中没有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;
}