1

I'm working on an iOS application that uses a lot of UIWebViews. Is there are way to prevent the UIWebView from popping out to Safari (iFrame code) but still load the page?

In other words return YES in webView:shouldStartLoadWithRequest:navigationType: but not let the web page pop out to Safari.

EDIT: The web view side has processes that need to be executed, which is why I need to return YES. But the processes also inadvertently cause the application to launch the URL in Safari. I'm looking for a way to intercept that, and choose whether or not to launch the URL in Safari.

kylesyoon
  • 131
  • 1
  • 8
  • What does "pop out to Safari" mean? If you return `YES` the page loads, doesn't it? Isn't that what you say you want? – matt Oct 16 '15 at 17:13
  • The web view side has processes that need to be executed, which is why I need to return `YES`. But the process also inadvertently causes the application to launch the URL in Safari. I'm looking for a way to intercept that, and choose whether or not to launch the URL in Safari. – kylesyoon Oct 16 '15 at 17:34
  • "But the process also inadvertently causes the application to launch the URL in Safari" I've never seen that happen. Safari launches if _you_ call `openURL`. Are these your own Web pages? Why is that happening? – matt Oct 16 '15 at 17:37
  • It is a hybrid application that relies on several views to be provided by it's mobile web counter part. They are required by the project. I can't say exactly why it's happening but the web side has requested that I handle the preventing Safari launch on my end. – kylesyoon Oct 16 '15 at 17:39
  • 1
    Well I think they are wrong. It's their fault, they have to prevent it. See this question and answers: http://stackoverflow.com/questions/27529966/completely-prevent-ios-web-app-from-opening-link-in-mobile-safari-even-with-lin Everything revolves around stuff internal to the web app. – matt Oct 16 '15 at 17:44

1 Answers1

0

Apple introduced a Safari View Controller on iOS 9. Safari View Controller is a pre-built browser that has all the bells and whistles of Mobile Safari, but can be presented without leaving your app.

First we need to import Safari Services

#import <SafariServices/SafariServices.h>

For Objective C:-

NSString *yourUrl = @"http://yourURL";
SFSafariViewController *svc= [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString: yourUrl]];
[self presentViewController:svc animated:YES completion:nil];

For Swift:-

let svc = SFSafariViewController(URL: NSURL(string: self.urlString)!)
self.presentViewController(svc, animated: true, completion: nil)
Vincent Joy
  • 2,598
  • 15
  • 25