Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SFSafariViewController done button not working

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.

like image 491
vishnu Avatar asked Dec 18 '15 14:12

vishnu


1 Answers

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.

like image 190
beyowulf Avatar answered Sep 28 '22 04:09

beyowulf