简体   繁体   English

如何在iOS 13上从LPMetadataProvider获取图像?

[英]How do you get the image out of LPMetadataProvider on iOS 13?

I want to use LPMetadataProvider (new on iOS 13) to get an image representation for a link (for instance the header image for a news article link). 我想使用LPMetadataProvider (iOS 13上的新增功能)来获取链接的图像表示(例如新闻文章链接的标题图像)。

let provider = LPMetadataProvider()
provider.startFetchingMetadata(for: URL(string: "https://someurl/")!) { (metadata, error) in
    metadata?.imageProvider?.howDoIGetTheImageOut()
})

Seemingly you can do loadDataRepresentation , but iOS 13 docs seem to indicate more of a recommendation to use loadPreviewImage , but I'm not sure what to pass or how to use that method. 看来您可以执行loadDataRepresentation ,但是iOS 13文档似乎表明更多建议使用loadPreviewImage ,但是我不确定该传递什么或如何使用该方法。

let metadataProvider = LPMetadataProvider()
let url = URL(string: "https://www.instagram.com/p/B1ZLpsZnwkY/")!

metadataProvider.startFetchingMetadata(for: url) { metadata, error in
  if error != nil {
    return
  }

  let IMAGE_TYPE = kUTTypeImage as String
  metadata?.imageProvider?.loadFileRepresentation(forTypeIdentifier: IMAGE_TYPE, completionHandler: { (url, imageProviderError) in
            if imageProviderError != nil {
                // The fetch failed; handle the error.
                return
            }
            let myImage = UIImage(contentsOfFile: (url?.path)!)
        })

   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS 13-UISegmentedControl-如何更改selectedSegment的角半径? - iOS 13 - UISegmentedControl - How do you change the corner radius of the selectedSegment? 在iOS中,如何从子ViewController获取图像? - In iOS how do you get an image from a sub ViewController? 如何获得对 iOS 13+ 中状态栏的引用? - How do I get a reference to the status bar in iOS 13+? 有没有办法使用 LPMetadataProvider 获取外部 URL 的 header 图像 (og:image) 的 url? - Is there a way to get the url of the header image (og:image) of an external URL using LPMetadataProvider? 你如何在 iOS 中裁剪图像 - How do you crop an image in iOS 如何使用imagemagick获得圆角,渐变抛光的iOS图标图像效果? - How do you get the rounded corner, gradient-polish iOS icon image effect with imagemagick? 如何从iOS应用的“ t.co” URL(Twitter专用图像)中获取图像? - How do you get an image from a “t.co” URL (Twitter specific images) for an iOS app? Xcode / ios:在让用户选择并显示图像之后,如何获得图像名称? - Xcode/ios: How do you get name of image after letting user select one and displaying it? iOS 13之前导航栏的大标题下边框怎么去掉? - How do you remove a navigation bar's large title bottom border before iOS 13? 如何显示加载指示器,然后将其与iOS中的内容交换出去? - How do you show a loading indicator and then swap it out with content in iOS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM