Stachuu
Stachuu

Reputation: 40

iOS Swift sharing PDF file, then delete

I have a question regarding sharing pdf files in swift. Sharing is quite simple and it already works in my app. I receive pdf file from backend, save it to local variable as bytes array, than save it in app cache directory and pass to UIActivityViewController.

Is there any way to receive some callback, that sharing action has been completed, or canceled, so I can immediately remove file from cache?

Thanks in advance for your help.

Upvotes: 0

Views: 557

Answers (2)

Roger Lee
Roger Lee

Reputation: 330

UIActivityViewController provides a completionWithItemsHandler property to handle this situation

let activityViewController = UIActivityViewController(activityItems: [url], applicationActivities: nil)
activityViewController.completionWithItemsHandler = { activityType, userTakeAnyAction, returnedItems, error in
    // Clean file here
    try? FileManager.default.removeItem(at: url)
}
self.present(activityViewController, animated: true)

Upvotes: 0

swiftHelp
swiftHelp

Reputation: 56

u could clean your cache when dismissing your UIActivityViewController

Upvotes: 0

Related Questions