I'm attempting to make a quick test to synchronize a file to iCloud. This is the simple snippet I have:
url = [[ubiquityContainerURL
URLByAppendingPathComponent: @"Documents"]
URLByAppendingPathComponent:@"test.txt"];
doc = [[CloudDocument alloc] initWithFileURL:url];
[doc saveToURL:[doc fileURL]
forSaveOperation:UIDocumentSaveForCreating
completionHandler:^(BOOL success) {
}];
Now I've tried to look around, and in other tutorials this seems to be the way they do it. The problem is that when the code is run, this exception gets thrown (at the line of [doc saveToURL]):
'NSInvalidArgumentException', reason: '* -[NSURL URLByAppendingPathExtension:]: component, components, or pathExtension cannot be nil.'
The method which runs this logic gets called right after fetching the ubiquity URL here:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
ubiquityContainerURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
if (ubiquityContainerURL != nil)
[self writeAllBytesToLocalFile:@""];
});
I've tried some different things to fix it but it keeps happening. Any idea what the problem might be?
Thank you all for your time :)