How to Launch Safari and Open Url from iOS App

Launching Safari App without using any specific url from an iOS App

Actually we can open a specific app from safari. You have to create a custom url scheme for the application and open that link from safari like any other link is opened from safari.

Create a custom url scheme like

myApp://

Then open it from safari e.g on onClick of button.

Open url and stay in app

The example your are showing is using the SFSafariViewController. This will show Safari in your app, this class is available in iOS 9 or newer.

You could use a check like this if you plan to support versions lower then iOS 9:

if ([SFSafariViewController class]) {
SFSafariViewController *viewController = [[SFSafariViewController alloc] initWithURL:url];
[self presentViewController:viewController animated:YES completion:nil];
} else {
WebViewController *viewController = [[WebViewController alloc] init];
viewController.url = url;
[self presentNavigationControllerWithViewController:viewController animated:YES completion:nil];
}

Here WebViewController is just a view controller with a UIWebView that will load the page. You can create your own tool bar like SFSafariViewController to go back/forward or open in Safari.



Related Topics



Leave a reply



Submit