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浏览器>>扩展。我们鼓励您将您的网站访问权限限制为“某些”(和明确的域名),除非您确实需要访问每个网站。

相关问题