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

Firebase Dynamic Links 導入事例

Chiharu Nameki
December 12, 2018

Firebase Dynamic Links 導入事例

CA.swift #7

Chiharu Nameki

December 12, 2018
Tweet

More Decks by Chiharu Nameki

Other Decks in Technology

Transcript

  1. Firebase Dynamic Linksͷಛ௃ • ແྉ • ຊՈͷυΩϡϝϯτ͕͔ͬ͠Γ͍ͯ͠Δ • OSS https://github.com/firebase

    • iOS, Android • ωΠςΟϒSDK • C++ SDK • UnityϓϥάΠϯ • ୹ॖURL & ΞφϦςΟΫεػೳ
  2. ओͳύϥϝʔλ ڞ௨ link σΟʔϓϦϯΫ iOS ibi iOSΞϓϦͷόϯυϧID isi App Store্ͷΞϓϦͷID

    ifl ະΠϯετʔϧ࣌ʹετΞҎ֎ʹભҠ͍ͤͨ͞৔߹ɺભҠઌURL Android apn AndroidΞϓϦͷύοέʔδ໊ afl ະΠϯετʔϧ࣌ʹετΞҎ֎ʹભҠ͍ͤͨ͞৔߹ɺભҠઌURL PC ofl PCͰlinkҎ֎ʹભҠ͍ͤͨ͞৔߹ɺભҠઌURL
  3. ϦονϓϨϏϡʔ༻ͷύϥϝʔλ΋ st λΠτϧ sd આ໌ si ը૾URL 300 x 200

    ϐΫηϧҎ্ɺ300 KB ະຬ SNS֦ࢄ࣌ͷݟͨ໨΍ετΞϓϨϏϡʔΛϦονʹͰ͖Δ Rich Link Preview
  4. ୹ॖURLػೳ • SDK΍REST APIͰURLΛ୹ॖͰ͖Δ • ୹ॖURLղܾ࣌ʹΫϦοΫ਺ͳͲ͕ूܭ͞ΕΔ • ूܭ݁Ռ͸REST APIͳͲͰऔಘՄೳ CLICK

    ΫϦοΫ਺ REDIRECT ετΞ(or ࢦఆͨ͠ભҠઌ)΁ͷૹ٬਺ APP_INSTALL Πϯετʔϧ਺ (AndroidͷΈ) APP_FIRST_OPEN ΠϯετʔϧޙΞϓϦΛ։͍ͨ਺ APP_RE_OPEN ΞϓϦΛ։͍ͨ਺
  5. Universal Links • υϝΠϯͱΞϓϦΛؔ࿈͚ͮΔ • αʔόʹઃఆϑΝΠϧ apple-app-site-association Λ഑ஔ • ΞϓϦͷEntitlementsͷAssociated

    Domainsʹ֘౰υϝΠϯΛهड़ • ΞϓϦͷΠϯετʔϧ / Ξοϓσʔτ࣌ʹؔ࿈෇͚͕ߦΘΕΔ • ϦϯΫΛ։͘ͱ͖ʹ֘౰ΞϓϦ͕͋ͬͨΒͦͷΞϓϦΛىಈ • ಉҰυϝΠϯ಺ͷ৔߹͸ΞϓϦΛىಈ͠ͳ͍
 ͢ͰʹϢʔβ͸αΠτ಺ͰαʔϏεΛମݧதͷͨΊ • ΞϓϦΛىಈ͢Δ͔͸௕ԡ͠ͷϝχϡʔͰϢʔβ͕બ୒Մೳ
 ࠷ޙͷબ୒͕OSʹهԱ͞ΕΔ iOS 9Ͱొ৔ͨ͠Deep Linkͷ࢓૊Έ
  6. // ΧελϜεΩʔϚURLΛFDLͱͯ͠ॲཧ͢΂͖͔Ͳ͏͔ func shouldHandleDynamicLink(fromCustomSchemeURL: URL) -> Bool // ΧελϜεΩʔϚURLΛύʔε func

    dynamicLink(fromCustomSchemeURL: URL) -> DynamicLink? // ௕͍Universal LinkΛύʔε func dynamicLink(fromUniversalLink: URL) -> DynamicLink? // Universal Link(௕͍URL΋୹ॖURL΋OK!)Λॲཧ͢Δศརϝιου func handleUniversalLink(_: URL, completion: (DynamicLink?, Error?)->()) -> BOOL // ୹ॖURLΛղܾ func resolveShortLink(_: URL, completion: (DynamicLink?, Error?)->()) -> BOOL // FDLͷ୹ॖURL͔Ͳ͏͔ func matchesShortLinkFormat(_: URL) -> Bool FIRDynamicLinks.h FDLॲཧΛ୲͏γϯάϧτϯ DynamicLinks.dynamicLinks() ͷI/F
  7. FIRDynamicLink.h FDLΛදݱ͢ΔΫϥε class DynamicLink: NSObject { private(set) var url: URL?

    /// Ϣʔβʔ͕Ұக͍ͯ͠Δ࣮֬ੑ private(set) var matchType: DLMatchType }
  8. ςετͰԿ౓΋ϦϯΫΛ౿ΜͩͨΊ͔ɺ ϦϯΫΛ౿ΜͰ͍ͳͯ͘΋ΞϓϦΛىಈͨ͠Β σΟʔϓϦϯΫॲཧ͕૸ΔΑ͏ʹͳͬͯ͠·͍· ͨ͠ ςετνʔϜ • ࣌ؒܦաͰղফ • efr=1Λࢦఆͯ͠ϓϨϏϡʔϖʔδΛόΠύε͍ͯͨ͠ •

    ͦͷ৔߹ΠϯετʔϧΛڬΜͰϢʔβͷ৘ใΛ࣮֬ʹҾ͖ܧ͙࢓૊Έ͸ͳ͍ • λΠϜελϯϓ΍༷ʑͳ৘ใΛ૊Έ߹Θͤͯແཧ΍Γߦ͍ͬͯΔͱࢥΘΕΔ • ͜͏ͨ͠ෆ࣮֬ੑ͕͋ΔͷͰɺԿ͔Λ֬ఆ͢ΔΑ͏ͳॲཧͷલʹ͸ ඞͣ֬ೝΛߦ͏΂͖
  9. let dl = DynamicLinks.dynamicLinks() if dl.matchesShortLinkFormat(url) && url.path != "/"

    { dl.handleUniversalLink(url) { [weak self] dynamicLink, _ in self?.dynamicLink = dynamicLink } } else { self.dynamicLink = dl.dynamicLink(fromUniversalLink: url) } W/AͰରԠ
  10. ϦϯΫΛ౿Ήͷ͕2ճ໨͔ͩΒɺදࣔ͞Εͳ͍Μ Ͱ͢Ͷʂ σβΠφʔ ͢Έ·ͤΜɺෆ۩߹Ͱ͢ɻ • ୹ॖURLͷղܾʹ͸ωοτϫʔΫ௨৴͕ඞཁ • Universal Linksड৴࣌ application(_:continue:restorationHandler:)

    ͸
 ΞϓϦ͕ActiveͰͳ͍͜ͱ΋͋Δ • ΞϓϦ͕ActiveͰͳ͍࣌ʹ௨৴͠Α͏ͱ͢Δ → ࣌ʑ௨৴Τϥʔ ୹ॖURLͷղܾʹ࣌ʑࣦഊ͍ͯͨ͠ ୹ॖURLͷղܾΛߦ͏λΠϛϯάΛௐ੔ͯ͠ରԠ
  11. ΞϓϦΛΠϯετʔϧࡁΈͳͷʹετΞʹߦͬͯ ͠·͏୺຤͕͋ΔΜͰ͚͢Ͳ... ϑϩϯτΤϯδχΞ • Πϯετʔϧ൑ఆʹUniversal LinksΛར༻͍ͯ͠Δ͕ނͷ՝୊
 Universal Links →ͲͪΒͰ։͔͘͸Ϣʔβ͕બ΂Δ
 ֘౰υϝΠϯΛΞϓϦͰ։͔ͳ͍Α͏ʹ͍ͯ͠Δέʔε

    • ετΞʹભҠ͢ΔͱΠϯετʔϧࡁΈͳͷͰΠϯετʔϧϘλϯ͕ ʮ։͘ʯϘλϯʹͳ͍ͬͯΔɻ • ͜ͷϘλϯͰ։͍ͨ৔߹ɺ࢒೦ͳ͕ΒσΟʔϓϦϯΫॲཧ͸ߦΘΕͳ͔ͬͨ • ϓϨϏϡʔϖʔδΛܦ༝͢Ε͹͋Δ͍͸…ʁ ະղܾ
  12. උߟ: App Store ConnectͷApp Analyticsͷύϥϝʔλ FDLʹ෇༩ՄೳɻͲͷΩϟϯϖʔϯ͕༗ޮ͔ͷ൑அࡐྉʹɻ • ct : Ωϟϯϖʔϯ໊,

    40จࣈҎ಺ • pt :ϓϩόΠμID, App Store ConnectͷʮΩϟϯϖʔϯϦϯΫΛ࡞੒ʯ ϖʔδͰ֬ೝͰ͖Δ • ݁Ռʹදࣔ͞ΕΔʹ͸5ͭҎ্ͷApple IDʹΠϯετʔϧ͞ΕΔඞཁ ͕͋Δ • ਍அ৘ใͷૹ৴ʹಉҙͨ͠ϢʔβͷΈͷ਺ࣈ