小编pvi*_*ito的帖子

如何在Safari App Extension中获得活动标签?

当我按照Apple的示例进行操作时,总是得到nil activeTab

override func toolbarItemClicked(in window: SFSafariWindow) {
    // This method will be called when your toolbar item is clicked.

    window.getActiveTab(completionHandler: { (activeTab) in
        print(activeTab)
        activeTab?.getActivePage(completionHandler:  { (activePage) in
            print(activePage)
            activePage?.getPropertiesWithCompletionHandler( { (properties) in
                print(properties)
                if properties?.url != nil {
                    let urlString = properties!.url.absoluteString
                    print("URL!", urlString)
                    let videoURL = self.youtubeDl(urlString: urlString)
                    if videoURL != nil {
                        window.openTab(with: videoURL!, makeActiveIfPossible: true, completionHandler: nil)
                    }
                }
            })
        })
    })
}
Run Code Online (Sandbox Code Playgroud)

safari macos swift safari-app-extension

3
推荐指数
2
解决办法
1786
查看次数

标签 统计

macos ×1

safari ×1

safari-app-extension ×1

swift ×1