This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import LinkPresentation | |
| class ViewController: UIViewController { | |
| private var metaData: LPLinkMetadata = LPLinkMetadata() | |
| @available(iOS 13.0, *) | |
| func fetchURLPreview(url: URL) { | |
| let metadataProvider = LPMetadataProvider() | |
| metadataProvider.startFetchingMetadata(for: url) { (metadata, error) in | |
| guard let data = metadata, error == nil else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func fetchPreviewManually(title: String, originalURL: URL, fileName: String, fileType: String) -> LPLinkMetadata? { | |
| let metaData = LPLinkMetadata() | |
| metaData.title = title | |
| metaData.originalURL = originalURL | |
| let path = Bundle.main.path(forResource: fileName, ofType: fileType) | |
| metaData.imageProvider = NSItemProvider(contentsOf: URL(fileURLWithPath: path ?? "")) | |
| return metaData | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @available(iOS 13.0, *) | |
| func fetchPreviewManually(title: String, originalURL: URL, fileName: String, fileType: String) -> LPLinkMetadata? { | |
| let metaData = LPLinkMetadata() | |
| metaData.title = title | |
| metaData.originalURL = originalURL | |
| let path = Bundle.main.path(forResource: fileName, ofType: fileType) | |
| metaData.imageProvider = NSItemProvider(contentsOf: URL(fileURLWithPath: path ?? "")) | |
| return metaData | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func addRichLinkToView(view: UIView, metadata: LPLinkMetadata) { | |
| linkView = LPLinkView(metadata: metadata) | |
| view.addSubview(linkView) | |
| linkView.frame = view.bounds | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| import LinkPresentation | |
| class ViewController: UIViewController { | |
| @IBOutlet weak var richView: UIView! | |
| private lazy var linkView = LPLinkView() | |
| private var metaData: LPLinkMetadata = LPLinkMetadata() { | |
| didSet { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class LinkPresentationItemSource: NSObject, UIActivityItemSource { | |
| var linkMetaData = LPLinkMetadata() | |
| //Prepare data to share | |
| func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata? { | |
| return linkMetaData | |
| } | |
| //Placeholder for real data, we don't care in this example so just return a simple string | |
| func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func getMetadataForSharingManually(title: String, url: URL, fileName: String, fileType: String) -> LPLinkMetadata { | |
| let linkMetaData = LPLinkMetadata() | |
| let path = Bundle.main.path(forResource: fileName, ofType: fileType) | |
| linkMetaData.iconProvider = NSItemProvider(contentsOf: URL(fileURLWithPath: path ?? "")) | |
| linkMetaData.originalURL = url | |
| linkMetaData.title = title | |
| return linkMetaData | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| import LinkPresentation | |
| class ViewController: UIViewController { | |
| @IBOutlet weak var sharingButton: UIButton! | |
| private var metaData: LPLinkMetadata = LPLinkMetadata() { | |
| didSet { | |
| DispatchQueue.main.async { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private let notificationFeedbackGenerator = UINotificationFeedbackGenerator() | |
| notificationFeedbackGenerator.notificationOccurred(.error) | |
| //or | |
| notificationFeedbackGenerator.notificationOccurred(.success) | |
| //or | |
| notificationFeedbackGenerator.notificationOccurred(.warning) |
OlderNewer