如何创建弹出框的内容?

时间:2019-01-15 08:51:34

标签: swift xcode macos popover safari-app-extension

我正在构建一个Safari应用程序扩展。该扩展包含一个弹出窗口,单击该扩展的工具栏项时会出现该弹出窗口。弹出视图包含一些按钮,这些按钮链接到用户可以执行的操作。我看到了弹出窗口,但是弹出窗口不包含内容。我也有自动布局的视图。 而且我没有错误消息。

class SafariExtensionHandler: SFSafariExtensionHandler

    override func validateToolbarItem(in window: SFSafariWindow, validationHandler: @escaping ((Bool, String) -> Void)) {
        validationHandler(true, "")
    }

    override func popoverViewController() -> SFSafariExtensionViewController {
        return SafariExtensionViewController.shared
    }

    override func popoverWillShow(in window: SFSafariWindow) {
        let unauthorizedId = UserDefaults.standard.string(forKey: "unauthorizedId")
        let trelloToken = UserDefaults.standard.string(forKey: "token")

        window.getActiveTab { (activeTab) in
            activeTab?.getActivePage(completionHandler: { (activePage) in
                activePage?.getPropertiesWithCompletionHandler( { (properties) in
                    SafariExtensionViewController.shared.onPopoverVisible(token: token, unauthorizedId: unauthorizedId)
                })
            })
        }
    }

class SafariExtensionViewController: SFSafariExtensionViewController {

    @IBOutlet weak var signInBtn: NSButton!
    @IBOutlet weak var goBtn: NSButton!
    static let shared = SafariExtensionViewController()

    private var domain: String = "https://google.com"

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    func onPopoverVisible(token: String?, unauthorizedId: String?) {
        NSLog("safaripl pop \(String(describing: unauthorizedId)) \(String(describing: token))")
        if (token == nil && unauthorizedId == nil ) {
            self.signInBtn.isHidden = false
            self.goBtn.isHidden = true
        } else if (token == nil && unauthorizedId != nil) {
            self.signInBtn.isHidden = true
            self.goBtn.isHidden = false
        }
    }

    @IBAction func signInBtnClick(_ sender: Any) {
        Util.openUrlInSafari(url: "https://google.com")
    }

    @IBAction func goBtnClick(_ sender: Any) {
        Util.openUrlInSafari(url: "https://google.com")
    }
}

0 个答案:

没有答案