Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 使用iOS共享/操作扩展拍摄主机应用程序的屏幕截图?_Swift_Algorithm_Ios8 Extension_Ios8 Share Extension_Webpage Screenshot - Fatal编程技术网

Swift 使用iOS共享/操作扩展拍摄主机应用程序的屏幕截图?

Swift 使用iOS共享/操作扩展拍摄主机应用程序的屏幕截图?,swift,algorithm,ios8-extension,ios8-share-extension,webpage-screenshot,Swift,Algorithm,Ios8 Extension,Ios8 Share Extension,Webpage Screenshot,我想知道如何使用共享/操作扩展拍摄iOS主机应用程序的屏幕截图 我的用例如下所示: 使用Safari浏览器访问网页(https,如gmail) 点击共享按钮并选择分机 扩展将拍摄当前网页的屏幕截图 这个用例的一个工作示例是 我试过以下方法 在UIWebView/WKWebkit上重新加载baseURI(loadRequest)(将无法访问https内容,如Gmail)。所以不做任何重新加载(可怕的屏幕截图不做重新加载btw) 使用ExtensionPreprocessingJS通过argumen

我想知道如何使用共享/操作扩展拍摄iOS主机应用程序的屏幕截图

我的用例如下所示:

  • 使用Safari浏览器访问网页(https,如gmail)
  • 点击共享按钮并选择分机
  • 扩展将拍摄当前网页的屏幕截图
  • 这个用例的一个工作示例是

    我试过以下方法

  • 在UIWebView/WKWebkit上重新加载baseURI(loadRequest)(将无法访问https内容,如Gmail)。所以不做任何重新加载(可怕的屏幕截图不做重新加载btw)
  • 使用ExtensionPreprocessingJS通过arguments.completionFunction函数获取DOM内容。我无法在这里提取document.body,尽管我可以获取源代码等。使用baseURI加载HtmlString会弄乱表示层
  • 在ExtensionPreprocessingJS中使用html2canvas获取图像,并将其作为子对象附加到宿主应用程序的网页中,但不知道如何提取图像。此外,一些网页(如Gmail)的图像丢失
  • Mobile Safari没有visibleContentsAsDataURL方法

  • 我认为一个可行的方法是在ExtensionPreprocessingJS中使用html2canvas,但是我如何保存这个图像呢

    编辑:因此下面的内容在模拟器中工作,但在设备上不工作。我目前也在寻找解决方案

    我认为这是一个很棒的屏幕截图应用程序使用的解决方案:

    func captureScreen() -> UIImage
    {
        // Get the "screenshot" view.
        let view = UIScreen.mainScreen().snapshotViewAfterScreenUpdates(false)
    
        // Add the screenshot view as a subview of the ShareViewController's view.
        self.view.addSubview(view);
    
        // Now screenshot *this* view.
        UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, false, 0);
        self.view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true)
        let image: UIImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        // Finally, remove the subview.
        view.removeFromSuperview()
    
        return image
    }
    

    谢谢你的主意!从我收集的信息来看,重点应该放在预处理JS上,JS负责抓取所有的显示内容。你解决了这个问题吗???@Andres,不是这样。。。你有什么想法?到目前为止我还不知道!如果我知道怎么做,我会把答案贴出来的!:)@安德烈斯,谢谢你!