Firebase Dynamic Links 導入事例

4ef794bdea63fc6153845bb26bac38a2?s=47 Chiharu Nameki
December 12, 2018

Firebase Dynamic Links 導入事例

CA.swift #7

4ef794bdea63fc6153845bb26bac38a2?s=128

Chiharu Nameki

December 12, 2018
Tweet

Transcript

  1. ߦ໦ ઍय़ʢͳΊ͖ ͪ͸Δʣ גࣜձࣾαΠόʔΤʔδΣϯτ Firebase Dynamic Links ಋೖࣄྫ CA.swift #7

    2018 Dec. 12 Twitter, Qiita, GitHub @Ridwy
  2. ࣗݾ঺հ ߦ໦ ઍय़ (ͳΊ͖ ͪ͸Δ) 2015೥த్ೖࣾ Ameba iOSΤϯδχΞ ݩ macOSιϑτ΢ΣΞΤϯδχΞ

    WWDC 2015, 2017ࢀՃ
  3. Firebase Dynamic Linksͱ͸ʁ

  4. ͜ͷػೳΛ࣮ݱͯ͘͠ΕΔϦϯΫ ΞϓϦͰ։͘

  5. ϢʔβΛঢ়ଶʹΑͬͯ࠷దͳભҠઌ΁ ΞϓϦͰ։͘ ΠϯετʔϧࡁΈ ະΠϯετʔϧͳΒετΞ΁ ΞϓϦىಈ
 &
 linkʹ֘౰͢Δը໘ʹભҠ
 (=σΟʔϓϦϯΫॲཧ)

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

    • iOS, Android • ωΠςΟϒSDK • C++ SDK • UnityϓϥάΠϯ • ୹ॖURL & ΞφϦςΟΫεػೳ
  7. ૝ఆ͞Ε͍ͯΔར༻γʔϯ • ΞϓϦ΁ͷಋઢ
 e.g. ʮΞϓϦͰ։͘ʯϘλϯ
 ΩϟϯϖʔϯLP಺ͷϘλϯ • ϓϩϞʔγϣϯ༻ͷϦϯΫΛSNSͰ֦ࢄ • ΞϓϦͷϢʔβಉ࢜ͰϦϯΫΛڞ༗

  8. Firebase Dynamic Links (Ҏ߱FDLͱུ)ͷྫ FDLͷ࣮ମ͸ඞཁͳ৘ใΛύϥϝʔλͱͯ࣋ͭ͠URL ͜ͷURLΛʮΞϓϦͰ։͘ʯϘλϯͳͲʹ࢓ࠐΜͰ࢖͏ https://example.page.link/? link=https://www.example.com/foo &apn=com.example.android &amv=3

    &ibi=com.example.ios &isi=1234567 ↑Subdomain
  9. ओͳύϥϝʔλ ڞ௨ link σΟʔϓϦϯΫ iOS ibi iOSΞϓϦͷόϯυϧID isi App Store্ͷΞϓϦͷID

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

    ϐΫηϧҎ্ɺ300 KB ະຬ SNS֦ࢄ࣌ͷݟͨ໨΍ετΞϓϨϏϡʔΛϦονʹͰ͖Δ Rich Link Preview
  11. ετΞϓϨϏϡʔ • App StoreભҠલʹFirebaseʹΑͬͯ
 දࣔ͞ΕΔϓϨϏϡʔ • ࠓͷॴiOSͷΈ • ΫϦοϓϘʔυΛར༻ͯ͠
 ϢʔβͷಉҰੑΛ୲อ

    • efr=1Λ͚ͭΔͱදࣔΛεΩοϓՄೳ
  12. ετΞϓϨϏϡʔ st, sd, si Λઃఆͨ͠ྫ

  13. શύϥϝʔλͱৄࡉ͸ެࣜυΩϡϝϯτͰʂ https://firebase.google.com/docs/dynamic-links/create-manually

  14. ϦϯΫͷੜ੒ํ๏ • खಈͰύϥϝʔλΛ૊Έཱͯ • Firebaseͷίϯιʔϧ্Ͱ࡞੒ • SDKͰ࡞੒ 3ͭͷํ๏͕͋Δ

  15. Firebaseίϯιʔϧ

  16. None
  17. ϦϯΫͷσόοά ϦϯΫʹEΛ͚ͭͯϒϥ΢βͰΞΫηεʂ

  18. iOS 9Ҏ߱ iOS 8

  19. ୹ॖURLػೳ • SDK΍REST APIͰURLΛ୹ॖͰ͖Δ • ୹ॖURLղܾ࣌ʹΫϦοΫ਺ͳͲ͕ूܭ͞ΕΔ • ूܭ݁Ռ͸REST APIͳͲͰऔಘՄೳ CLICK

    ΫϦοΫ਺ REDIRECT ετΞ(or ࢦఆͨ͠ભҠઌ)΁ͷૹ٬਺ APP_INSTALL Πϯετʔϧ਺ (AndroidͷΈ) APP_FIRST_OPEN ΠϯετʔϧޙΞϓϦΛ։͍ͨ਺ APP_RE_OPEN ΞϓϦΛ։͍ͨ਺
  20. ※ Firebaseͷίϯιʔϧ্Ͱ࡞੒Ͱ͖ΔURL΋୹ॖURL
 ίϯιʔϧ্Ͱ࡞੒ͨ͠৔߹ɺूܭ݁Ռ΋ίϯιʔϧʹදࣔ͞ΕΔ

  21. ୹ॖURLػೳ • ୹͍ (TwitterͳͲͰͷ֦ࢄʹศརʣ • ಺༰͕૝૾Ͱ͖ͳ͍ͷͰΞϓϦ͕ϋοΫ͞Εʹ͍͘ • Firebase͕ूܭΛߦͬͯ͘ΕΔ • ΞϓϦͰड৴ޙɺ௨৴ΛߦͬͯϦϯΫΛղܾ͢Δඞཁ͕͋Δ


    εϜʔζͳσΟʔϓϦϯΫॲཧͷ๦͛ʹͳΔέʔε΋ Pros. Cons.
  22. iOSΞϓϦʹ૊ΈࠐΉ

  23. • Universal Links • ΧελϜεΩʔϚURLʹΑΔΞϓϦىಈ FDLʹར༻͞Ε͍ͯΔiOSͷ࢓૊Έʹ͍ͭͯগ͠ ΠϯετʔϧࡁΈ൑ఆɾΞϓϦىಈʹ͸ҎԼ͕ར༻͞Ε͍ͯΔ

  24. Universal Links • υϝΠϯͱΞϓϦΛؔ࿈͚ͮΔ • αʔόʹઃఆϑΝΠϧ apple-app-site-association Λ഑ஔ • ΞϓϦͷEntitlementsͷAssociated

    Domainsʹ֘౰υϝΠϯΛهड़ • ΞϓϦͷΠϯετʔϧ / Ξοϓσʔτ࣌ʹؔ࿈෇͚͕ߦΘΕΔ • ϦϯΫΛ։͘ͱ͖ʹ֘౰ΞϓϦ͕͋ͬͨΒͦͷΞϓϦΛىಈ • ಉҰυϝΠϯ಺ͷ৔߹͸ΞϓϦΛىಈ͠ͳ͍
 ͢ͰʹϢʔβ͸αΠτ಺ͰαʔϏεΛମݧதͷͨΊ • ΞϓϦΛىಈ͢Δ͔͸௕ԡ͠ͷϝχϡʔͰϢʔβ͕બ୒Մೳ
 ࠷ޙͷબ୒͕OSʹهԱ͞ΕΔ iOS 9Ͱొ৔ͨ͠Deep Linkͷ࢓૊Έ
  25. Universal Links ஫ҙ఺ • ΞϓϦΛ։͘ڍಈ͸ɺϢʔβͷ୺຤ͷOSʹΑ੍ͬͯޚ͞Ε͍ͯΔ • ڍಈΛม͑ΔτϦΨʔ͸ΞϓϦͷΞοϓσʔτ • apple-app-site-association͚ͩॻ͖׵͑ͯ΋ޮՌ͕ͳ͍

  26. ͍͟ಋೖ

  27. ಋೖͷྲྀΕ 1. FirebaseϓϩδΣΫτʹΞϓϦΛ݁ͼ͚ͭΔ 2. SDKΛΠϯετʔϧ 3. Firebase Dynamic Links ίϯιʔϧͰαϒυϝΠϯΛऔಘ

    4. EntitlementsΛઃఆ 5. ड৴ॲཧΛ࣮૷
  28. FirebaseϓϩδΣΫτʹΞϓϦΛ݁ͼ͚ͭΔ ࢦࣔ௨ΓΞϓϦͷ৘ใΛೖྗ & ηοτΞοϓ ஫ҙ νʔϜIDʹ͸ x νʔϜID Ͱ͸ͳ͘ o

    Provisioning ProfileͷApp IDͷPrefix Λઃఆʢݹ͍ΞϓϦͰ͸ҟͳΔ͜ͱ͕͋Δʣ
  29. SDKΛΠϯετʔϧ CocoaPodsΛར༻ pod 'Firebase/Core' pod 'Firebase/DynamicLinks' $pod install

  30. FirebaseίϯιʔϧͰαϒυϝΠϯΛऔಘ 5ݸ·Ͱొ࿥/࡟আͰ͖Δ

  31. ૣ͍ऀউ͔ͪͱࢥ͍͖΍…ʁ amebloΛऔΖ͏ͱͨ͠Β͜Μͳը໘͕ ΞϝʔόϒϩάͷυϝΠϯ͸ ameblo.jp Ͱ͢ ͋Γ͕ͱ͏͍͟͝·͢ʂ

  32. EntitlementsΛઃఆ Associated Domainsʹઌ΄Ͳऔಘͨ͠υϝΠϯΛ௥Ճ

  33. ड৴ॲཧΛ࣮૷ ४උ import Firebase // Firebaseͷڞ௨ΠϯελϯεΛηοτΞοϓ FirebaseApp.configure()

  34. ड৴ॲཧΛ࣮૷ ΞϓϦʹ౉ͬͯདྷͨURL͔ΒSDKͰlinkΛऔΓग़͠ɺ֘౰ը໘΁ભҠ URLड৴ϝιου • ΧελϜεΩʔϚURL
 application(_:open:options:)
 • Universal Links
 application(_:continue:restorationHandler:)


    
 ※ ىಈ࣌͸launchOptionsʹ΋URL͕౉ͬͯ͘ΔͷͰ
 ΑΓૣ͘ॲཧΛ։࢝Մೳ

  35. Firebase iOS SDK FDLͷॲཧΛߦ͏I/F FIRDynamicLinks.h ಡΜͰΈΔ

  36. ͓͜ͱΘΓ SwiftͰهࡌ͍ͯ͠·͕͢ ࣮ࡍ͸Objective-CͰ͢ CA.swift

  37. // ΧελϜεΩʔϚ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
  38. FIRDynamicLink.h FDLΛදݱ͢ΔΫϥε class DynamicLink: NSObject { private(set) var url: URL?

    /// Ϣʔβʔ͕Ұக͍ͯ͠Δ࣮֬ੑ private(set) var matchType: DLMatchType }
  39. ࣮૷ͯ͠ΈͨΒ…

  40. ςετͰԿ౓΋ϦϯΫΛ౿ΜͩͨΊ͔ɺ ϦϯΫΛ౿ΜͰ͍ͳͯ͘΋ΞϓϦΛىಈͨ͠Β σΟʔϓϦϯΫॲཧ͕૸ΔΑ͏ʹͳͬͯ͠·͍· ͨ͠ ςετνʔϜ • ࣌ؒܦաͰղফ • efr=1Λࢦఆͯ͠ϓϨϏϡʔϖʔδΛόΠύε͍ͯͨ͠ •

    ͦͷ৔߹ΠϯετʔϧΛڬΜͰϢʔβͷ৘ใΛ࣮֬ʹҾ͖ܧ͙࢓૊Έ͸ͳ͍ • λΠϜελϯϓ΍༷ʑͳ৘ใΛ૊Έ߹Θͤͯແཧ΍Γߦ͍ͬͯΔͱࢥΘΕΔ • ͜͏ͨ͠ෆ࣮֬ੑ͕͋ΔͷͰɺԿ͔Λ֬ఆ͢ΔΑ͏ͳॲཧͷલʹ͸ ඞͣ֬ೝΛߦ͏΂͖
  41. ͨ·ʹىಈޙ͙͢Ͱ͸ͳ͘ɺগ͠஗Εͯදࣔ͞ ΕΔΜ͚ͩͲେৎ෉ʁ σΟϨΫλʔ σόοάͨ͠ΒɺͳΜͱ Firebase iOS SDKͷ matchesShortLinkFormat(_:) ͕௕͍63-ʹରͯ͠΋ true

    ͜ͷ࣌͸௕͍··ͷURLͩͬͨͷͰ
 ड৴͔ͯ͠Βൃಈ͢Δ·ͰλΠϜϥά͸ͳ͍͸ͣ
  42. firebase-ios-sdk/Firebase/DynamicLinks/Utilities/FDLUtilities.m let url = URL(string: "https://hoge.page.link/?abc=123")! url.path // -> "/"

    ୹ॖURLͱޡ൑ఆ͞ΕΔ௕͍URLͷྫ
  43. 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ͰରԠ
  44. ϦϯΫΛ౿Ήͷ͕2ճ໨͔ͩΒɺදࣔ͞Εͳ͍Μ Ͱ͢Ͷʂ σβΠφʔ ͢Έ·ͤΜɺෆ۩߹Ͱ͢ɻ • ୹ॖURLͷղܾʹ͸ωοτϫʔΫ௨৴͕ඞཁ • Universal Linksड৴࣌ application(_:continue:restorationHandler:)

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

    • ετΞʹભҠ͢ΔͱΠϯετʔϧࡁΈͳͷͰΠϯετʔϧϘλϯ͕ ʮ։͘ʯϘλϯʹͳ͍ͬͯΔɻ • ͜ͷϘλϯͰ։͍ͨ৔߹ɺ࢒೦ͳ͕ΒσΟʔϓϦϯΫॲཧ͸ߦΘΕͳ͔ͬͨ • ϓϨϏϡʔϖʔδΛܦ༝͢Ε͹͋Δ͍͸…ʁ ະղܾ
  46. ӡ༻͢Δʹ͋ͨͬͯߦͬͨࣄ

  47. ӡ༻୲౰ऀʹଘࡏΛ஌ͬͯ΋Β͏ ษڧձΛ։࠵

  48. ؆୯͔ͭ҆શʹ࢖͑ΔΑ͏ʹ͢Δ Ωϟϯϖʔϯ୲౰ऀ͕ϦϯΫΛ࡞੒ & ؅ཧ & ෼ੳͰ͖ΔΑ͏ʹ • linkΛೖྗ͢Δͱ௕͍FDL͕ੜ੒͞ΕΔεϓϨουγʔτΛ༻ҙ • ΫϦοΫɺΞϓϦॳճىಈɺΞϓϦ࠶ى͸AmebaͰར༻͍ͯ͠Δ

    طଘͷ࢓૊ΈͰૹ৴
  49. උߟ: App Store ConnectͷApp Analyticsͷύϥϝʔλ FDLʹ෇༩ՄೳɻͲͷΩϟϯϖʔϯ͕༗ޮ͔ͷ൑அࡐྉʹɻ • ct : Ωϟϯϖʔϯ໊,

    40จࣈҎ಺ • pt :ϓϩόΠμID, App Store ConnectͷʮΩϟϯϖʔϯϦϯΫΛ࡞੒ʯ ϖʔδͰ֬ೝͰ͖Δ • ݁Ռʹදࣔ͞ΕΔʹ͸5ͭҎ্ͷApple IDʹΠϯετʔϧ͞ΕΔඞཁ ͕͋Δ • ਍அ৘ใͷૹ৴ʹಉҙͨ͠ϢʔβͷΈͷ਺ࣈ
  50. ॴײ • ؔ࿈ٕज़͸ηΩϡϦςΟͱརศੑͷτϨʔυΦϑ • ඞཁे෼ͳػೳ • ಛʹಉҰυϝΠϯ಺ͰͷΞϓϦಋઢʹྑ͍ • ϦϦʔεͨͯ͠ͳͷͰυΩυΩ͠ͳ͕Βݟक͍ͬͯ·͢

  51. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠