$30 off During Our Annual Pro Sale. View Details »

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. .BTUFSJOH TIBSFTIFFUQSFWJFX  QPUBUPUJQT F[VSB

  2. F[VSB w 1PEDBTU"VEJPCPPL IUUQTNPPLNPPLSBEJPDPN w -*/&DPSQ w -*/&ϊϕϧ։ൃ୲౰

  3. /FX J04d dJ04

  4. 2͜ͷ1SFWJFX෦෼ɺԿ͔ରԠ͕ඞཁʁ

  5. 2͜ͷ1SFWJFX෦෼ɺԿ͔ରԠ͕ඞཁʁ 4%,ଆͰద੾ʹදࣔͯ͘͠ΕΔ৔߹΋͋Δ

  6. 2͜ͷ1SFWJFX෦෼ɺԿ͔ରԠ͕ඞཁʁ ΞϓϦ։ൃऀଆͰมߋ͕ඞཁͳ৔߹΋͋Δ

  7. ରԠલ  γΣΞ͢Δίϯςϯπ w 63-ίϯςϯπ΁ͷ63- w ςΩετϋογϡλά౳

  8. ରԠલ ରԠޙ63-ͷQSFWJFXΛදࣔ

  9. ରԠޙ63-ͷQSFWJFXΛදࣔ ରԠલ

  10. UIActivityViewController

  11. let activityVC = UIActivityViewController( activityItems: [shareItem], applicationActivities: nil) self.present(activityVC, animated:

    true, completion: nil)
  12. activityItems: [URL(Web)] activityItems: [URL(file path)] activityItems: [Text] ࣗಈతʹద੾ͳදࣔΛͯ͘͠ΕΔ৔߹ ྫ

  13. activityItems: [URL, Text] activityItems: [UIImage] activityItems: [NSData] activityItems: [Text, UIImage]

    վળͷ༨஍͕͋Δ৔߹ ྫ ΞϓϦΞΠίϯ
  14. ଞʹ΋͍Ζ͍Ζͳύλʔϯ͕͋Δ͚ΕͲʜ

  15. ͜ΕΛԡ͓͚͑ͯ͞͹େৎ෉ʂ

  16. ϙΠϯτ 1SFWJFX͞ΕΔίϯςϯπͷ༏ઌ౓

  17. let activityVC = UIActivityViewController( activityItems: [...], applicationActivities: nil) self.present(activityVC, animated:

    true, completion: nil)
  18. 6*"DUJWJUZ*UFN4PVSDF4USJOH63-%BUB 6**NBHF౳ ϙΠϯτ 1SFWJFX͞ΕΔίϯςϯπͷ༏ઌ౓ ஫ ͜Ε͸%PDVNFOUʹ໌จԽ͞Ε͓ͯΒͣɺ ࢲݸਓͰͷ࣮ݧΛجʹͨ͠ௐࠪ݁ՌͰ͢ɻ ެࣜ৘ใͰ͸ͳ͍͜ͱΛ͝ཹҙ͍ͩ͘͞ɻ

  19. activityItems: [URL, String] 6*"DUJWJUZ*UFN4PVSDF4USJOH63-*NBHF ϙΠϯτ 1SFWJFX͞ΕΔίϯςϯπͷ༏ઌ౓

  20. activityItems: [ItemSource(URL), String] ϙΠϯτ 1SFWJFX͞ΕΔίϯςϯπͷ༏ઌ౓ 6*"DUJWJUZ*UFN4PVSDF4USJOH63-*NBHF

  21. ϙΠϯτ -1-JOL.FUBEBUB

  22. -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?
  23. 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 } }
  24. 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
  25. 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 }
  26. 88%$ ʮ&NCFEEJOHBOE4IBSJOH7JTVBMMZ3JDI-JOLTʯ IUUQTEFWFMPQFSBQQMFDPNWJEFPTQMBZXXED -1-JOL.FUBEBUBपΓͷৄࡉ

  27. -1-JOL.FUBEBUBΛ࢖͏ํ๏ͷ·ͱΊ w ํ๏ w -1-JOL.FUBEBUBʹλΠτϧ΍ΞΠίϯ౳ͷ৘ใΛೖΕΔ w ্هΛ6*"DUJWJUZ*UFN4PVSDFͷϝιουܦ༝Ͱ౉͢ w PQUJPOBM౉ͨ͠-1-JOL.FUBEBUBͷQSPQFSUZΛߋ৽͢Δ w

    ஫ҙ఺ 4IBSFઌʹ΋-1-JOL.FUBEBUB͸౉͞ΕΔ 4IBSFઌͰ࢖ΘΕΔՄೳੑ͕͋Δ
  28. 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͸౉͞ΕΔ
  29. ࢀߟจݙ w -1-JOL.FUBEBUB IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOMJOLQSFTFOUBUJPO MQMJOLNFUBEBUB w &NCFEEJOHBOE4IBSJOH7JTVBMMZ3JDI-JOLT IUUQTEFWFMPQFSBQQMFDPNWJEFPTQMBZXXED w -JOL1SFTFOUBUJPO

    IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOMJOLQSFTFOUBUJPO