Open LPLinkView url in app instead of Safari

Viewed 221

For the newly supported LPLinkView in the LinkPresentation framework, is there any way to change the default action (i.e., open the url in Safari) after clicking on it? I've read through the doc and found nothing.

My implementation:

guard let url = URL(string: URL_STRING) else { return }

let provider = LPMetadataProvider()
let linkView = LPLinkView(url: url)
provider.startFetchingMetadata(for: url) { (metadata, err) in 
    guard let metadata = metadata, err == nil else { return }
    DispathQueue.main.async {
        linkView.metadata = metadata
    }
}
myStackView.insertArrangedSubview(linkView, at: 0)
1 Answers

Not directly but yes!

For example, while using it inside UICollectionView, if you:

  1. add isUserInteractionEnabled = false property to LPLinkView
  2. Use func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) delegate method
  3. You can hijack the tap and use a SFSafariViewController you can open it in app.

Same for thing applies to UIView you just need to add an empty view on top of LPLinkView with alpha = 0.

Related