S
S
s0L2014-01-28 18:40:41
Objective-C
s0L, 2014-01-28 18:40:41

How to write data to end of file using NSFileCoordinator while saving UIDocument to iCloud?

Have your own UIDocument, redefined

writeContents:toURL:forSaveOperation:originalContentsURL:error:
and in it I try to write data to the end of the file using , but it only turns out to overwrite the file, all other options do not work, it gives an error. There is another method[NSFileCoordinator coordinateWritingItemAtURL::::]
coordinateReadingItemAtURL:options:writingItemAtURL:options:error:byAccessor:
but as I understand it, it is for different files, it is not clear how it can be used in my case. There is very little information on this subject. :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2014-01-28
@alexyat

Adding to the file is done through the handler, for example like this:

NSString *dir = [pathCache stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.download", [itemToDownload fileName]]];
    if(data)
        [tmpData appendData:data];
    if(![tmpData length])
        return;
    NSFileHandle *handle = [NSFileHandle fileHandleForWritingAtPath:dir];
    [handle seekToEndOfFile];
    [handle writeData:tmpData];
    [handle closeFile];
    [tmpData setLength:0];

where tmpData is NSData

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question