Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Mastering
 share sheet preview

Yuka Ezura
November 11, 2019

Mastering
 share sheet preview

Yuka Ezura

November 11, 2019
Tweet

More Decks by Yuka Ezura

Other Decks in Programming

Transcript

  1. -1-JOL.FUBEBUB An object that contains metadata about a URL https://developer.apple.com/documentation/linkpresentation/lplinkmetadata

    •var originalURL: URL? •var url: URL? •var title: String? •var iconProvider: NSItemProvider? •var imageProvider: NSItemProvider? •var videoProvider: NSItemProvider? •var remoteVideoURL: URL?
  2. class ShareActivityItemSource: NSObject, UIActivityItemSource { func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) ->

    LPLinkMetadata? { linkMetadata } func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any { placeholder } func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? { item } }
  3. class ShareActivityItemSource: NSObject, UIActivityItemSource { func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) ->

    LPLinkMetadata? { let linkMetadata = LPLinkMetadata() linkMetadata.title = "custom title" linkMetadata.iconProvider = NSItemProvider(contentsOf: imageURL) return linkMetadata } linkMetadata.iconProvider (or imageProvider) linkMetadata.title
  4. class ShareActivityLazyLoadItemSource: NSObject, UIActivityItemSource { init(_ url: URL) { self.originalURL

    = url self.imageURL = saveImageInTemporaryDir(#imageLiteral(resourceName: "ezura"), fileName: "shareImage")! super.init() linkMetadata.title = "placeholder title" linkMetadata.originalURL = originalURL linkMetadata.iconProvider = NSItemProvider(contentsOf: imageURL) linkMetadata.imageProvider = NSItemProvider(contentsOf: imageURL) metadataProvider.startFetchingMetadata(for: originalURL) { [linkMetadata] metadata, error in linkMetadata.title = metadata?.title linkMetadata.url = metadata?.url linkMetadata.originalURL = metadata?.originalURL linkMetadata.iconProvider = metadata?.iconProvider linkMetadata.imageProvider = metadata?.imageProvider } } func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata? { return linkMetadata }
  5. 3FDBQ w ϙΠϯτ1SFWJFX͞ΕΔίϯςϯπͷ༏ઌ౓ 6*"DUJWJUZ*UFN4PVSDF5FYU63-%BUB 6**NBHF౳  1SFWJFX͍ͨ͠ίϯςϯπΛ6*"DUJWJUZ*UFN4PVSDFܦ༝Ͱ౉͢  ෳ਺ͷ6*"DUJWJUZ*UFN4PVSDF͕͋Δ৔߹͸ઌউͪ 

    w ϙΠϯτ-1-JOL.FUBEBUB w -1-JOL.FUBEBUBʹλΠτϧ΍ΞΠίϯ౳ͷ৘ใΛೖΕΔ w ্هΛ6*"DUJWJUZ*UFN4PVSDFͷϝιουܦ༝Ͱ౉͢ ஫ҙ4IBSFઌʹ΋-1-JOL.FUBEBUB͸౉͞ΕΔ