有没有办法在iCloud上复制文件(db.Sqlite)而不必删除本地文件? 我有这个代码:
NSLog(@"File does not exist in cloud");
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"db.sqlite"];
NSURL *fromURL = [NSURL URLWithString:writableDBPath];
BOOL success = [fileManager setUbiquitous:YES itemAtURL:fromURL destinationURL:ubiquityURL error:&error];
if (success)
{
NSLog(@"copied to icloud");
}
该文件已复制到iCloud,但已从本地删除,但我也希望您留在本地。它是如何工作的?
答案 0 :(得分:0)
您可以使用copyItemAtURL:toURL:error:
。像这样:
NSLog(@"File does not exist in cloud");
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"db.sqlite"];
NSURL *fromURL = [NSURL URLWithString:writableDBPath];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
BOOL success = [fileManager copyItemAtURL:fromURL toURL:ubiquityURL error:&error];
if (success)
{
NSLog(@"copied to icloud");
}
});