Problem
What I still have is code that creates a new local file and deletes the iCloud file.
Can I rename an iCloud document so that it stays in iCloud?
GarageBand can do this. You can rename the song iCloud. After renaming, the song is still in iCloud. However, GarageBand is an Apple app, so it can use private apis.
My current code is:
- (void)moveFrom:(NSURL*)sourceURL moveTo:(NSString*)destinationName completion:(void (^)())completion { MyDocument *document = [[MyDocument alloc] initWithFileURL:sourceURL]; [document openWithCompletionHandler:^(BOOL success) { NSURL *fileURL = [self.localRoot URLByAppendingPathComponent:destinationName]; DLog(@"Create %@", fileURL); [document saveToURL:fileURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) { NSLog(@"Saved %@", fileURL); [document closeWithCompletionHandler:^(BOOL success) {
Update: not lucky yet
I found that -setUbiquitous:itemAtURL:destinationURL:error: cannot be used to rename documents.
If I call [setUbiquitous: NO itemAtURL: oldLocalURL destinationURL: newLocalURL error: & error] in an already local file, then:
Domain Error = NSCocoaErrorDomain Code = 512 "Operation could not be completed. (Cocoa error 512.)" UserInfo = 0x1fdf6730 {NSURL = File: // localhost / var / mobile / Applications / 4BABA000-B100-49FC-B928-B0F403FC75FF / Documents /LocalDrawing.td2/, NSUnderlyingError = 0x20940e80 "Operation could not be completed. (Error LibrarianErrorDomain 2 - Unable to disable synchronization on an unsynchronized item.)"}
If I call [setUbiquitous: YES itemAtURL: oldCloudURL destinationURL: newCloudURL error: & error] in an already cloud file, then:
Domain Error = NSCocoaErrorDomain Code = 512 "Operation could not be completed. (Cocoa error 512.)" UserInfo = 0x208e9820 {NSURL = File: // localhost / var / mobile / Library / Mobile% 20Documents / 22DR89XVRF ~ com ~ opcoders ~ triangle -draw / Documents / CloudDrawing.td2 /, NSUnderlyingError = 0x208d45b0 "The operation could not be completed. (Error LibrarianErrorDomain 2 - Unable to enable synchronization of the synchronized item.)"}
Thus, -setUbiquitous:itemAtURL:destinationURL:error: cannot be used to rename documents.
source share