Reputation: 357
I'm looking for a possibility to invoke an alert view from a website.
I'm pretty sure that this works somehow because if go through configuring your Apple ID and stuff like that in the App Store you are navigating through webviews and not a native environment (prior to iOS 7!).
Apple uses alert view and action sheets and date picker there so there has to be a way to do so.
I wasn't able to find anything useful on the web nor in the docs.
Cheers
Constantin
Upvotes: 1
Views: 281
Reputation: 2797
To achieve this you can use redirects, set javascript onClick function to some DOM element.
f.e
javascript function callNativeAlert(message) {
window.location = "showAlert://"+message;
}
On UIWebView delegate's you can catch such redirect then show your UIAlertView
and ignore loading this page by returning NO
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if ([[request.URL scheme] isEqualToString:@"showAlert"]) {
//TODO: Show your alert here, or execute any native method
NSLog(@"The message is %@", [request.URL host])
...
// Always return NO not to allow `UIWebView` process such links
return NO;
}
....
}
Note: this code has been written from memory
Note2: of course it works if you can modify both javascript and native application
Upvotes: 1