How can I close a Safari App Extension popover programmatically?

前端 未结 2 1598
萌比男神i
萌比男神i 2021-02-08 00:13

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

相关标签:
2条回答
  • 2021-02-08 00:50

    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;
        }
    }
    
    0 讨论(0)
  • 2021-02-08 00:56

    I did it by calling dismiss method like below

    @IBAction func onLoginBtnClicked (_ sender: Any) {
        NSLog("Button clicked")
        self.dismiss(self)
    }
    
    0 讨论(0)
提交回复
热议问题