Cordoba 3.1 open link in Safari on iOS6

I am building an iOS application with Cordova 3.1. I have a link that I would like to open in Safari. I installed the org.apache.cordova.inappbrowser plugin and it worked fine on my iPhone (iOS 7) and on the simulator (iOS5; iOS6.1; iOS7), but if I try (iOS6) on all devices, that works.

Does anyone know how to fix this or try it on a real device running iOS6? I use this code to open a link:

window.open('http://www.google.nl', '_system'); 
+6
source share
2 answers

I implemented this through my own side (Objective-C)

Add this method to 'MainViewController.m'

 - (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { NSURL *url = [request URL]; NSString *str = url.absoluteString; NSRange range = [str rangeOfString:@"http://"]; NSRange range1 = [str rangeOfString:@"https://"]; if (range.location != NSNotFound || range1.location != NSNotFound) { [[UIApplication sharedApplication] openURL:url]; return NO; } else { return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ]; } } 

This applies to both the "http" and "https" links for iOS6 and iOS7 and opens the link in the device’s default browser.

+3
source

I know this is an old question, but I came across it too and just wrote a small plugin to help with it. The answer to Siddhartha is almost right, but when I used it, it intercepted all web requests, including my index.html , and that seems to have moved my application to Safari. I needed a way to handle only explicit requests, so I could open certain (external) URLs in Safari.

There are many similar questions about Phonegap, which seems to insert special handling for window.open with _system . That would be nice, but Cordoba has no such function.

In the end, I wrote a small plugin that embeds enough Objective-C (closely modeled by Siddhartha's answer), but due to the magic of the plugins, it can be executed on demand using cordova.exec . I would like this to be fixed in window.open to achieve the same functionality as Phonegap, but this will be for another day, and this does not affect this answer.

As far as I can tell, in modern Cordoba this is the only viable strategy.

0
source

Source: https://habr.com/ru/post/955721/


All Articles