In the web page, for ‘Choose Image’ Button write a Java Script function . iOS supports custom URL schemes provided with syntax below
scheme://host/path?query
Example Java script function in your .html :
<p class="btn-upload" onclick="onUploadButtonClick()" >
<span> Upload File </span>
</p>
<script>
function onUploadButtonClick() {
window.location = "ios://button-upload”;
}
</script>
In your class .m file, inside Webview delegate method webView:shouldStartLoadWithRequest:request:navigationType
compare the host. if it matches invoke your objective c function to open UIImagePicker in the app.
#pragma mark - UIWebView Delegates
- (void) webViewDidFinishLoad:(UIWebView *)webView {
//Do after web view load.
}
- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType;
{
// get the action from the path
NSString *actionType = request.URL.host;
if ([actionType isEqualToString:@“button-upload”]) {
// do something in response to your javascript action
// if you used an action parameters dict, deserialize and inspect it here
[self openImagePicker]; //Cal your method to open UIImagePicker
}
// make sure to return NO so that your webview doesn't try to load your made-up URL
return NO;
}
Bonus : Make sure you have added App Transport Security Key in your info.plist
.