Question

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 :)

Was it helpful?

Solution

All right so I figured out what the problem was. The UIDocument instance doc was trying to append a file extension to the final path in its initialize method.

Unfortunately I had overwritten the -(NSString)savingFileType method in my UIDocument subclass in an incorrect way, which made it return a nil string to the initialize method, thus attempting to append a nil NSString object to the file path.

So in any case others bump into this problem, you can try to remove your custom overwritten method to see if that fixes the problem :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top