1

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

Constantin Jacob
  • 357
  • 1
  • 3
  • 12

2 Answers2

1

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

Injectios
  • 2,777
  • 1
  • 30
  • 50
0

You can use simple JS function alert('message').