Search code examples
javascriptiosswiftwkwebviewimagepicker

Catch photo upload in WKWebview


I would like to intercept photo uploading which was started from javascript from site loaded with WKWebview. Normally I would implement:

`func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {`

but since photo uploading does not comes from me I am not able to set delegate.

I had one try with overriding UIImagePickerController and setting delegate in viewDidLoad but it seems to not working at all.


Solution

  • It's possible:

    extension UIImagePickerController {
    
         open override func viewDidLoad() {
            super.viewDidLoad()
            self.delegate = picker
         }
    }
    

    where picker has to implement UIImagePickerControllerDelegate