Last active
March 9, 2020 14:51
-
-
Save wata/149f4e3bbee7318bc437773cce902a7d to your computer and use it in GitHub Desktop.
Batch uploader with UIActivityViewController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func viewDidLoad() { | |
super.viewDidLoad() | |
let items: [[Any]] = [ | |
["Foo", URL(string: "http://www.africau.edu/images/default/sample.pdf")!] | |
["Bar", URL(string: "http://www.africau.edu/images/default/sample.pdf")!] | |
] | |
presentActivityViewControllerRecursively(items: items) { (error, items) in | |
if let error = error, let items = items { | |
print("Failed to complete activity items: \(items)") | |
return | |
} | |
print("done") | |
} | |
} | |
private func presentActivityViewControllerRecursively(items: [[Any]], completion: @escaping (Error?, [Any]?) -> Void) { | |
var _items = items | |
let vc = UIActivityViewController(activityItems: _items.remove(at: 0), applicationActivities: nil) | |
vc.completionWithItemsHandler = { [weak self] (_, completed, items, error) in | |
guard completed else { | |
completion(error, items) | |
return | |
} | |
if _items.isEmpty { | |
completion(nil, nil) | |
return | |
} | |
self?.presentActivityViewControllerRecursively(items: _items, completion: completion) | |
} | |
present(vc, animated: true, completion: nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment