I\'m building a Safari App Extension using XCode 8.3 and Swift 3, following the Safari App Extension Programming Guide. The extension includes a popover that appears when the ex
I'll add an answer in case anyone stumbles upon this question.
A dissmissPopover() instance method has been added to the SFSafariExtensionViewController class. This can be used to programatically close the popover.
The default template given when creating a Safari App Extension in XCode gives you a SafariExtensionViewController class that extends SFSafariExtensionViewController and holds a shared instance as a static field called 'shared', so you can call the dismissPopover() method from that instance.
For example:
class SafariExtensionHandler: SFSafariExtensionHandler {
    func myFunc() {
        // do stuff;
        SafariExtensionViewController.shared.dismissPopover()
        // do other stuff;
    }
}
                                                                        I did it by calling dismiss method like below
@IBAction func onLoginBtnClicked (_ sender: Any) {
    NSLog("Button clicked")
    self.dismiss(self)
}