2016-09-27 63 views
1

當我按照蘋果的例子,我總是得到nilactiveTab如何在Safari應用程序擴展中獲取活動選項卡?

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) 
        } 
       } 
      }) 
     }) 
    }) 
} 

回答

2

你的Safari瀏覽器應用擴展只能訪問網站上的擴展裝置配置用於訪問的標籤。

在你的Info.plist,驗證SFSafariWebsiteAccess dictionary

  • 擁有級別等於 「一些」 或 「所有」。

  • 具有允許域陣列中列出的所有必需的結構域(如果級別=「一些」)。

要知道,你的擴展網站的訪問權限都顯示在Safari瀏覽器>>擴展。我們鼓勵您將您的網站訪問權限限制爲「某些」(和明確的域名),除非您確實需要訪問每個網站。

相關問題