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.

1 Answer 1

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.