How can I close a Safari App Extension popover programmatically?

岁酱吖の 提交于 2019-12-03 06:02:12

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)
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!