Stop the current executable writeToFile:

I have some code that writes some objects PDFDocument

to a user selected destination. This works great.

Perhaps some of these files (selected by the user) could be quite large (maybe hundreds of megabytes) and now I'm wondering if there is an option to cancel the current call writeToFile:withOptions:

(for example, the user changes his mind and wants to stop it).

+3


source to share


1 answer


I doubt you can do it with this method as it does not provide any undo functionality.

I suggest you use the method dataRepresentation

PDFDocument

to get the PDF data first. Then you can split the data using NSData

s subdataWithRange:

. And then you can write data to the file sequentially using the NSFileHandle

s fileHandleForWritingToURL:error:

, writeData:

and methods closeFile

.



By writing it in chunks like this from the main thread to for

-loop say, you can undo it at any time.

+1


source







All Articles