访问Safari 12 Extension Popover中的当前页面信息

问题描述 投票:0回答:1

我正在尝试将活动选项卡的页面信息显示在弹出窗口中。我能够让它显示当前页面的URL或标题,但它需要打开和关闭扩展名弹出窗口两次。

我相信这是因为获取该信息,下面的代码依赖于completionHandler,使其异步。

SFSafariApplication.getActiveWindow { (window) in
    window?.getActiveTab { (tab) in
        tab?.getActivePage(completionHandler: { (page) in
            page?.getPropertiesWithCompletionHandler( { (properties) in
                self.pageTitle = properties?.title ?? "Unknown"
                self.ActivePageTitle.stringValue =  self.pageTitle
            })
        })
    }
}

第一次打开弹出窗口时,它会显示一个空白文本区域,但第二次它将在之前加载信息并正确显示。

我已经尝试在viewDidLoad()中运行它但是只在第一次打开popover时触发它。

viewWillAppear()中运行时,我得到以下错误:

pid(17738)/euid(501) is calling TIS/TSM in non-main thread environment,
ERROR : This is NOT allowed. Please call TIS/TSM in main thread!!!

我想可能切换扩展使用command而不会工作,但后来意识到你不能以编程方式打开弹出窗口。

一旦异步数据请求完成,我是否必须切换到UITableView或具有reloadData()函数的东西才能运行?

MacOS 10.14.4 | Safari 12.1 | Xcode 10.2

swift safari safari-extension sfsafariviewcontroller
1个回答
-1
投票

您可以在SafariExtensionHandler中获取SFSafariPageProperties对象,并在SafariExtensionViewController中使用此对象。

- (void)popoverWillShowInWindow:(SFSafariWindow *)window {
    [window getActiveTabWithCompletionHandler:^(SFSafariTab *activeTab) {
        [activeTab getActivePageWithCompletionHandler:^(SFSafariPage *page) {
            [page getPagePropertiesWithCompletionHandler:^(SFSafariPageProperties *properties) {
                // Now you can use "properties" in viewController using shareObject
            }];
        }];
    }];
}

现在需要在viewWillAppear中再次获取SFSafariPage的属性。

© www.soinside.com 2019 - 2024. All rights reserved.