【问题标题】:How to share the contents of a UIWeb view controller to Social sites?如何将 UIWeb 视图控制器的内容分享到社交网站?
【发布时间】:2018-01-02 06:23:29
【问题描述】:

我对如何将 Swift 中的 UIWebView 的内容共享到 Facebook 和 Twitter 等社交网站感到困惑。我看过很多关于如何分享它们的视频和文章。但找不到答案。

我正在 Xcode 上制作一个新闻应用程序,其中视图控制器包含一个 UIWebView,用于显示该特定日期的文章。我的 UIWebView 成功加载数据,但我找不到将内容分享到社交应用的代码。

请帮忙。

【问题讨论】:

标签: ios swift3 uiwebview xcode8.2


【解决方案1】:

您可以分享网页视图中加载的网址,或者如果您想分享内容,您可以在缓存中检查相同的内容,如果没有找到内容,您需要从网址下载内容。

喜欢:

if let url = aWebView.request?.url {
        //check in response cache for the pdf content else download from url
        let response = URLCache.shared.cachedResponse(for: aWebView.request!)
        if let pdfData = response?.data {

            //share content from pdfData to social
        } else if let pdfData = NSData(contentsOf: url) {
            //print("from url")
            //share content from pdfData social
        } else {
            self.showAlert(with: "Sorry", message: "Unable to share at this , please try again")
        }
    } else {
        //nothing found to share
        self.showAlert(with: "Sorry", message: "Unable to share at this , please try again")
    }

编辑:分享网址

对于社交分享,有属性 url,或者您也可以根据需要设置它的初始文本

你可以得到这样的网址:

let url = aWebView.request?.url

并分享这个获得的网址。

【讨论】:

  • 感谢您的回答。我还可以知道如何共享网络视图的 URL 吗?尝试了许多其他方法,但想有第二个意见@Van
  • 根据我对您问题的理解更新了答案。希望有帮助
猜你喜欢
  • 1970-01-01
  • 2013-05-25
  • 2013-11-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多