Created
August 21, 2020 13:06
-
-
Save SwapnanilDhol/90dba97b4f07c97ef9f6110534de26b2 to your computer and use it in GitHub Desktop.
A UIActivity Helper Class to show thumbnail preview and text in the share sheet title area
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
// | |
// ItemDetailSource.swift | |
// StickerTweet | |
// | |
// Created by Swapnanil Dhol on 7/9/20. | |
// Copyright © 2020 Swapnanil Dhol. All rights reserved. | |
// | |
import UIKit | |
import LinkPresentation | |
class ItemDetailSource: NSObject { | |
let name: String | |
let image: UIImage | |
init(name: String, image: UIImage) { | |
self.name = name | |
self.image = image | |
} | |
} | |
extension ItemDetailSource: UIActivityItemSource { | |
func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any { | |
image | |
} | |
func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? { | |
image | |
} | |
func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata? { | |
let metaData = LPLinkMetadata() | |
metaData.title = name | |
metaData.imageProvider = NSItemProvider(object: image) | |
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
//Code used for StickerCards. Please make changes as neccesaary. | |
private func saveCardWithBackground() { | |
guard let stickerImage = generateCardWithBackground() else { return } | |
let ac = UIActivityViewController(activityItems: [ItemDetailSource(name: "Tweet by \(tweet?.name ?? "Unknown")", image: stickerImage)], applicationActivities: nil) | |
if let popoverController = ac.popoverPresentationController { | |
popoverController.sourceView = self.view | |
popoverController.sourceRect = CGRect(x: self.view.bounds.midX, | |
y: self.view.bounds.midY, | |
width: 0, | |
height: 0) | |
popoverController.permittedArrowDirections = [] | |
} | |
self.present(ac, animated: true) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, very helpfull