I want to present a rich link in my app and also send those data to my server. I need to access the image inside the view of LPLinkView.
how can I access the parameters inside it? (like: image, description, title, icon, and ext...)
I want to present a rich link in my app and also send those data to my server. I need to access the image inside the view of LPLinkView.
how can I access the parameters inside it? (like: image, description, title, icon, and ext...)
Copyright © 2021 Jogjafile Inc.
Unfortunately, you can't access any internal properties of an
LPLinkView
, but you can easily create your own view. TheLPLinkMetadata
object has everything you need, you just need to know how to extract the images from itsiconProvider
andimageProvider
, which are subclasses ofNSItemProvider
.UIKit (iOS)
You can use
NSItemProvdier
'sloadObject(ofClass:)
method to easily get aUIImage
. This works becauseUIImage
conforms to theNSItemProviderReading
protocol.SwiftUI
SwiftUI's
Image
is astruct
, so it cannot conform toNSItemProviderReading
. It's easiest to use the UIKit code above to obtain aUIImage
and instantiate a SwiftUIImage
from that.AppKit (macOS)
Unlike its
UIImage
sister,NSImage
does not conform toNSItemProviderReading
, which means you'll have to useNSItemProvdier
's olderloadItem(forTypeIdentifier:options:)
method.You'll need to specify the
typeIdentifier
and initialize theNSImage
fromData
yourself, but otherwise it's pretty much the same.