7

I have a test ViewController which is embedded in a NavigationController. In test ViewController I have a WebView button. When I click on that button it navigates to SafariViewController and it's loading given URL. In that WebView when I click on "Done" button it's calling delegate method called safariViewControllerDidFinish. But that SafariViewController is not being dismissed.

Here is my code.

- (IBAction)bannerWebviewAction:(id)sender {
    NSURL *urls = [NSURL URLWithString:@"http://www.google.com"];
    SFSafariViewController safariVC = [[SFSafariViewController alloc] initWithURL:urls];
    [self showViewController:safariVC sender:nil];
    safariVC.delegate = self;
}

#pragma SFSafariViewControllerDelegate
-(void)safariViewControllerDidFinish:(SFSafariViewController *)controller {
    // Done button pressed
    [controller dismissViewControllerAnimated:YES completion:nil];  
}

Done button is calling, view is not dismissing. I checked log for the self and controller, both are correct.

SwiftArchitect
  • 47,376
  • 28
  • 140
  • 179
vishnu
  • 715
  • 9
  • 20

1 Answers1

16

You should not say

[self showViewController:safariVC sender:nil];

You should say

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

SFSafariViewControllers are meant to be presented modally and will dismiss itself when done is pressed.

vishnu
  • 715
  • 9
  • 20
beyowulf
  • 15,101
  • 2
  • 34
  • 40