How can I close a Safari App Extension popover programmatically?

前端 未结 2 1597
萌比男神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;
        }
    }
    

提交回复
热议问题