Ololo
Ololo

Reputation: 15

Open url and stay in app

I want to open any url in app and stay in app like this done in Skype. It opens safari page with "done" button in top left corner but you still in Skype.Can anyone help me? Example

Upvotes: 1

Views: 2417

Answers (3)

rckoenes
rckoenes

Reputation: 69459

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.

Upvotes: 5

MD.
MD.

Reputation: 1167

If you want to open any web page within your app,

Create UIViewController subclass and follow the steps

  1. Add Property for url (NSString or NSURL)
  2. Add "Done" Button on navigation bar (dismiss the view controller on click)
  3. Add UIWebView
  4. load the request in WebView in viewDidAppear

To open page from other ViewController:

WebViewController *webVC=[self.storyboard instantiateViewControllerWithIdentifier:@"WebViewControllerIdentifier"];
webVC.url=@"http://example.com";


[self presentViewController:webVC animated:YES completion:nil];

Upvotes: 1

Andrey Chernukha
Andrey Chernukha

Reputation: 21808

You can use simply SFSafariViewController. This is the simplest way to achieve what you want. I believe Skype uses exactly that. You can put it inside UINavigationController or whatever another container view controller

SFSafariViewController

Upvotes: 0

Related Questions