Save 37% off PRO during our Black Friday Sale! »

Firebase for iOS 初手〇〇

Firebase for iOS 初手〇〇

モバイルアプリ開発に欠かせないmBaaS であるFirebase についての解説。FirebaseはGoogle がモバイルアプリ向けに提供しているクラウドサービスのブランド名だが機能が
多すぎて何から手をつけていいか分からなくなる。

本プレゼンテーションではiOSアプリ開発であれば初手に何をすべき核について解説している。

0fb0b8c6eecbc8e0a3981501f6a6fea6?s=128

notoroid

May 25, 2021
Tweet

Transcript

  1. 'JSFCBTFGPSJ04 ॳखʓʓ

  2. ࣗݾ঺հ

  3. ೳొཁ !OPUPSPJE w J04ΞϓϦ։ൃऀ w ԰߸͍Γ·͢ిࢉاը w !OPUPSPJE w !JSJNBTV

    w ࠷ۙͷಈ޲ w ϒϩά࡮৽͠·ͨ͠
  4. ॆిใࠂ͞Μ #BUUFSFDFJWFS w όοςϦʔϞχλʔ ϢʔςΟϦςΟʔ  w ࠷େ୆ ࣮ػ ϦϞʔτ୆

     w ख࣋ͪͷJ1IPOF͔Βଞʹ͍࣋ͬͯΔ J1IPOF J1BEͳͲͷػثͷόοςϦʔঢ়ଶ֬ ೝՄೳ w ࣗ୐ʹ͋ΔJ1IPOFͷόοςϦʔঢ়ଶ֬ೝՄ ೳ
  5. ॆిใࠂ͞Μ #BUUFSFDFJWFS w "QQMF8BUDIରԠ w $PNQMJDBUJPOTରԠ w ॆి׬ྃ௨஌ w ॆి׬ྃΛ఻͑ͯ͘ΕΔ௨஌Λ௥Ճ

    w ҎԼʹࢦఆ͢Δ͜ͱͰόοςϦʔΛέ Ξ͢Δ͜ͱ͕Մೳ w Կ͔ͱߴ͍J1IPOFΛ௕࣋ͪͤ͞Δͷʹ༗༻
  6. ࿩͢͜ͱ w 'JSFCBTFͷτϐοΫ w ϞόΠϧΞϓϦ։ൃͰͷ'JSFCBTFॳख

  7. ࿩͞ͳ͍͜ͱ w ͷ(PPHMF*0ʹ͍ͭͯ w 'JSFCBTFNFTTBHJOH w 'JSFCBTF$MPVE'VODUJPOT w 'JSFCBTF$MPVE)PTUJOH

  8. ୊໨ w 'JSFCBTF֓ཁ w 'JSFCBTFͷ࠷ۙͷτϐοΫ w J1IPOFΞϓϦϓϩδΣΫτ'JSFCBTFॳखϜʔϒ

  9. 'JSFCBTF֓ཁ

  10. 88%$։࠵ؒۙ 

  11. ͜ͷ࣌ظ͸Appleͷωλ͕ͳ͍

  12. ͔ΘΓʹ(PPHMFͷΧϯϑΝϨϯ ε͸͋Δ (PPHMF*0

  13. ϞόΠϧΞϓϦʹ͔͔ͤͳ͍ 'JSFCBTFͷॳखʹ͍ͭͯઆ໌

  14. 'JSFCBTFͱ͸

  15. 'JSFCBTFͱ͸ w (PPHMF͕ఏڙ͢ΔϞόΠϧΞϓϦ༻N#BB4 ͷϒϥϯυ w 'JSFCBTFͱ͍͏ϦΞϧλΠϜσʔλϕʔ εͷઌۦ͚ͷϕϯνϟʔΛങऩ w ͦͷ··ϒϥϯυͱͯ͠࢖༻ w

    ଞαʔϏε 'BCSJD ΋ٵऩ w (PPHMF$MPVEQMBUGPSNΛج൫ʹϞόΠ ϧαʔϏεʹదͨ͠ܗͰఏڙ w  ैྔ՝ۚ੡
  16. ϓϥοτϑΥʔϜαʔϏεରԠ w ϞόΠϧ޲͚ w 'JSFCBTFJ044%, w 'JSFCBTF"OESPJE4%, w 'JSFCBTF+BWBTDSJQU4%, 8FCϑϩϯτΤϯυ޲͚

     w 'JSFCBTF"ENJO4%, αʔόʔαʔόʔϨε޲͚ ϞόΠϧΞϓϦͱόοΫΤϯυͰͷ'JSFCBTFػೳݺͼग़͠Λαϙʔτ
  17. 'JSFCBTFͷػೳ ൈਮ ʙ"VUIFOUJDBUJPO Ϣʔβʔೝূ ʙ$SBTIMZUJDT Ϋϥογϡ৘ใڞ༗ ʙ$MPVE.FTTBHJOH ϓογϡ௨஌ ʙ$MPVE'VODUJPOT αʔόʔϨείϯϐϡʔςΟϯά

    ʙ$MPVE'JSFTUPSF ϦΞϧλΠϜσʔλϕʔε ʙ)PTUJOH ϗεςΟϯάαʔϏε ʙ"QQ%JTUSJCVUJPO ݕূΞϓϦͷ഑෍ ʙ4UPSBHF ετϨʔδαʔϏε ʙ3FBMUJNF%BUBCBTF ϦΞϧλΠϜσʔλϕʔε ถࠃͷΈ ๛෋ͳػೳͱ͙͢࢖͑Δརศੑ
  18. ϞόΠϧϓϥοτϑΥʔϜΛαϙʔτ͠ όοΫΤϯυ΋ରԠ͢ΔαʔϏεʹ੒௕

  19. w ϓϩδΣΫτ୯ҐͰαʔϏε؅ཧ w ϓϩδΣΫτʹෳ਺ΞϓϦࢦఆՄೳ w ͭͷαʔϏεͰෳ਺ϓϥοτϑΥʔϜɺ αʔϏε͕ࢀরՄೳ

  20. 'JSFCBTFʹؔ͢Δ࿩୊

  21. 'JSFCBTFʹؔ͢Δ࿩୊ w 4XJGU1BDLBHF.BOBHFSରԠ w 'JSFCBTF'JSFTUPSF4XJGUͷػೳڧԽ w σʔλఆٛΛ4XJGUͷ$PEBCMFͰࢦఆՄೳʹ

  22. 4XJGU1BDLBHF.BOBHFSରԠ

  23. 4XJGU1BDLBHF.BOBHFSରԠ w 4XJGU1BDLBHF.BOBHFS w "QQMFۘ੡ͷϛυϧ΢ΣΞಋೖػೳ w 9DPEF্ͷૢ࡞Ͱ؆ܿ w ⁶$PDPBQPET $BSUIBHF

    w 9DPEFͰରԠ
  24. %FSJWFE%BUBΛফڈͨ͠ࡍʹ4XJGU1BDLBHFTͷύοέʔδࢀর ʹࣦഊ͢Δࡍͷରॲํ๏ JSJNBTVDPNEFSJWFEEBUBTXJGUQBDLBHFT 4XJGU1BDLBHF.BOBHFSͷศར৘ใ

  25. 'JSFCBTF'JSFTUPSF4XJGUͷػೳڧԽ w σʔλετΞ $MPVE'JSFTUPSF ͸0CKFDUJWF$΋αϙʔτ w 4XJGU޲͚ػೳ֦ு͸ఏڙ͞Ε͍ͯͳ͍ w (PPHMFۘ੡ͷ'JSFCBTF'JSFTUPSF4XJGUͰ4XJGU޲͚ػೳ֦ு w

    4XJGUͷ$PEBCMFରԠTUSVDUDMBTTͰσʔλఆٛՄೳʹ
  26. import SwiftUI import FirebaseFirestore import FirebaseFirestoreSwift struct Activity: Codable {

    @DocumentID var id: String? var title: String var description: String var timstamp: Date } struct ActivityView: View { @State var count = 1 var body: some View { Button { let db = Firestore.firestore() let ref = db.collection("activities") count = count + 1 let now = Date() let activity = Activity(id: nil, title: "\(count)", description: "Activity number \(count)/", timstamp: now) do { let newDocReference = try ref.addDocument(from: activity) print("Book stored with new document reference: \(newDocReference)") } catch { print(error) } } label: { Text("Add Activity") } } }
  27. import SwiftUI import FirebaseFirestore import FirebaseFirestoreSwift struct Activity: Codable {

    @DocumentID var id: String? var title: String var description: String var timstamp: Date } struct ActivityView: View { @State var count = 1 var body: some View { Button { let db = Firestore.firestore() let ref = db.collection("activities") count = count + 1 let now = Date() let activity = Activity(id: nil, title: "\(count)", description: "Activity number \(count)/", timstamp: now) do { let newDocReference = try ref.addDocument(from: activity) print("Book stored with new document reference: \(newDocReference)") } catch { print(error) } } label: { Text("Add Activity") } } } ඞཁͳJNQPSU
  28. import SwiftUI import FirebaseFirestore import FirebaseFirestoreSwift struct Activity: Codable {

    @DocumentID var id: String? var title: String var description: String var timstamp: Date } struct ActivityView: View { @State var count = 1 var body: some View { Button { let db = Firestore.firestore() let ref = db.collection("activities") count = count + 1 let now = Date() let activity = Activity(id: nil, title: "\(count)", description: "Activity number \(count)/", timstamp: now) do { let newDocReference = try ref.addDocument(from: activity) print("Book stored with new document reference: \(newDocReference)") } catch { print(error) } } label: { Text("Add Activity") } } } σʔλఆٛ
  29. import SwiftUI import FirebaseFirestore import FirebaseFirestoreSwift struct Activity: Codable {

    @DocumentID var id: String? var title: String var description: String var timstamp: Date } struct ActivityView: View { @State var count = 1 var body: some View { Button { let db = Firestore.firestore() let ref = db.collection("activities") count = count + 1 let now = Date() let activity = Activity(id: nil, title: "\(count)", description: "Activity number \(count)/", timstamp: now) do { let newDocReference = try ref.addDocument(from: activity) print("Book stored with new document reference: \(newDocReference)") } catch { print(error) } } label: { Text("Add Activity") } } } σʔλΛ௥Ճ͢Δ
  30. 'JSFTUPSF΁൓ө

  31. 'JSFCBTFॳखʓʓ

  32. 'JSFCBTF͸ͳΜͰ΋Ͱ͖Δ͕

  33. ͱ͸ݴͬͯ΋

  34. ػೳ͕ଟͯ͘ԿΛ͍͍͔ͯ͠ Θ͔Βͳ͍

  35. 'JSFCBTFΛ࢖͏ΞϓϦͷ ৽ن্ཱͪ͛͸ͦ͏ଟ͘ͳ͍

  36. 'JSFCBTFΛ࢖͏ࡍʹ͸ ॳखΛ͔ͬ͢Γ๨Ε͍ͯΔ

  37. ࠓճ͸'JSFCBTFಋೖͷ ࠷ॳͷखॱΛղઆ

  38. ಋೖϞσϧ

  39. J04ΞϓϦ 'JSFCBTF ଞαʔϏε 'JSFCBTF $MPVE'VODUJPOT 􀟜 'JSFCBTF $MPVE'JSFTUPSF 'JSFCBTF $MPVE.FTTBHJOH

    'JSFCBTF $SBTIMZUJDT 0UIFS 4FSWJDF 'JSFCBTF GPSJ04 "1/T (PPHMF$MPVE 1SBUGPSN 8FC)PPL )5513FRVFTU "ENJO4%, 1VTI/PUJ fi DBUJPO 1VTI/PUJ fi DBUJPOT
  40. J04ΞϓϦ 'JSFCBTF ଞαʔϏε 'JSFCBTF $MPVE'VODUJPOT 􀟜 'JSFCBTF $MPVE'JSFTUPSF 'JSFCBTF $MPVE.FTTBHJOH

    'JSFCBTF $SBTIMZUJDT 0UIFS 4FSWJDF 'JSFCBTF GPSJ04 "1/T (PPHMF$MPVE 1SBUGPSN 8FC)PPL )5513FRVFTU "ENJO4%, 1VTI/PUJ fi DBUJPO 1VTI/PUJ fi DBUJPOT ͜ͷൣғΛͳΜͱ͔͍ͨ͠
  41. ૝ఆΞϓϦ ϓϩδΣΫτ໊͸"DUJWJUZ5FTU ίʔυྔͷ౎߹্4XJGU6* ͓ͦΒ͘6*,JUɺ'MVUUFSͰ΋աఔมΘΒͳ͍͸ͣ  લఏ 'JSFCBTFίϯιʔϧ΁ϩάΠϯՄೳ $PDPBQPET࢖༻ Ϋϥογϡ৘ใΛऩू͢Δ ϢʔβʔೝূΛ༗ޮʹ͢Δ

    "VUIFOUJDBUJPO  4JHO*OXJUI"QQMF 'JSFTPSF'JSFTUPSFΛ༗ޮԽ ͓஌ΒͤҰཡػೳΛ୲ΘͤΔͨΊͷج൫ͱͯ͠σʔλετΞΛར༻͍ͨ͠
  42. ҎԼʹެ։த OPUPSPJE'JSFCBTF'JSTU.PWF'JSTU TUFQTUPVTJOH'JSFCBTFGPSJ04 HJUIVCDPNOPUPSPJE'JSFCBTF'JSTU.PWF

  43. ·ͣ͸'JSFCBTFίϯιʔϧʹͯ 'JSFCBTFϓϩδΣΫτΛ࡞੒

  44. None
  45. ·ͣ࠷ॳʹ͢Δ͜ͱ͸

  46. ՝ۚϓϥϯͷมߋ

  47. None
  48. $MPVE'VODUJPOTͰͷར༻࣌ʹ ੍໿ͳͲ͕͋ΔͷͰͬ͞͞ͱ੾Γସ͑

  49. None
  50. ࡞ۀ.BDͰ৽نϓϩδΣΫτ "DUJWJUZ5FTU࡞੒

  51. #VOEMF*EFOUJ fi FSΛίϐʔ

  52. 'JSFCBTFͰϓϩδΣΫτʹ J04ΞϓϦΛ௥Ճ

  53. J04ϘλϯΛλοϓ

  54. #VOEMF*EFOUJ fi FSΛೖྗ

  55. (PPHMF4FSWJDF*OGPQMJTU Λμ΢ϯϩʔυͯ͠9DPEF ϓϩδΣΫτʹ௥Ճ

  56. ҎԼ͸'JGSFCBTFͷࢦࣔ௨Γʹ ਐΊΔ͕ɺ

  57. 1PE fi MF $PDPBQPET༻ఆٛ ͸ ͪ͜ΒΛ࢖༻͢Δ

  58. # Uncomment the next line to define a global platform

    for your project platform :ios, '14.5' target 'ActivityTest' do # Comment the next line if you don't want to use dynamic frameworks use_frameworks! pod 'Firebase/Auth' pod 'Firebase/Crashlytics' pod 'Firebase/Firestore' pod 'FirebaseFirestoreSwift' pod 'Firebase/Messaging' end
  59. # Uncomment the next line to define a global platform

    for your project platform :ios, '14.5' target 'ActivityTest' do # Comment the next line if you don't want to use dynamic frameworks use_frameworks! pod 'Firebase/Auth' pod 'Firebase/Crashlytics' pod 'Firebase/Firestore' pod 'FirebaseFirestoreSwift' pod 'Firebase/Messaging' end ೝূ༻ $SBTIMZUJDTू༻ σʔλετΞ༻ ϓογϡ௨஌༻
  60. $PDPBQPETΛΠϯετʔϧޙɺ ௥Ճ͞ΕͨϫʔΫεϖʔεϑΝΠϧ "DUJWJUZ5FTUYDXPSLTQBDF  Λ։͚͹'JSFCBTFͷಋೖ׬ྃ

  61. ֤ػೳ͝ͱʹಋೖ࡞ۀ͕ ඞཁʹͳΔ

  62. αϯϓϧίʔυղઆ

  63. ҎԼʹެ։த OPUPSPJE'JSFCBTF'JSTU.PWF'JSTU TUFQTUPVTJOH'JSFCBTFGPSJ04 HJUIVCDPNOPUPSPJE'JSFCBTF'JSTU.PWF

  64. "DUJWJUZ5FTU w $SBTIMZUJDTૄ௨༻7JFX w 4JHO*OXJUI"QQMF֬ೝ༻7JFX w σʔλετΞ֬ೝ༻7JFX

  65. "DUJWJUZ5FTU fi OJTI ʹ׬੒ίʔυ

  66. $PDPBQPEͷΠϯετʔϧ (PPHMF4FSWJDF*OGPQMJTU ͕ඞཁ

  67. "DUJWJUZ5FTU fi OJTI "DUJWJUZ5FTU "DUJWJUZ5FTU"QQTXJGU import SwiftUI @main struct ActivityTestApp:

    App { @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate var body: some Scene { WindowGroup { // original view ContentView() // step1) for Crashlytics activate // CrashView() // step2) for Signin with Apple test // SigninView() // step3) Firestore test // ActivityView() } } }
  68. "DUJWJUZ5FTU fi OJTI "DUJWJUZ5FTU "DUJWJUZ5FTU"QQTXJGU import SwiftUI @main struct ActivityTestApp:

    App { @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate var body: some Scene { WindowGroup { // original view ContentView() // step1) for Crashlytics activate // CrashView() // step2) for Signin with Apple test // SigninView() // step3) Firestore test // ActivityView() } } } $SBTIMZUJDTૄ௨༻ 7JFX 4JHO*OXJUI"QQMF ֬ೝ༻7JFX σʔλετΞ֬ೝ༻7JFX
  69. "DUJWJUZ5FTU"QQͷίϝϯτΞ΢τ͞Ε ͨ7JFXͱ'JSFTUPSFίϯιʔϧͷࢦࣔ௨ Γʹ͢Ε͹جຊ0,

  70. ͨͩ͠$SBTIMZUJDTͷૄ௨ςετ࣌ɺ 9DPEFͷσϑΥϧτઃఆͱ ৯͍ҧ͏ͷͰ஫ҙ

  71. $SBTIMZUJDTͱ9DPEFઃఆ %FCVH 3FMFBTFઃఆ 9DPEFͷ΢ΟβʔυͰͷઃఆ %&#6(@*/'03."5*0/@'03."5 %8"3' %8"3'XJUIE4:.'JMF $SBTIMZUJDTͷૄ௨ςετ ࢖༻༗ແ ૄ௨ςετʹ࢖༻͢Δ

    ૄ௨ςετʹ࢖༻͠ͳ͍
  72. $SBTIMZUJDTͱ9DPEFઃఆ %FCVH 3FMFBTFઃఆ 9DPEFͷ΢ΟβʔυͰͷઃఆ %&#6(@*/'03."5*0/@'03."5 %8"3' %8"3'XJUIE4:.'JMF $SBTIMZUJDTͷૄ௨ςετ ࢖༻༗ແ ૄ௨ςετʹ࢖༻͢Δ

    ૄ௨ςετʹ࢖༻͠ͳ͍ %8"3'XJUIE4:.'JMF͕ ඞཁͳͷʹૄ௨ςετʹ࢖༻͢Δ %FCVH൛͸ແޮʹͳ͍ͬͯΔ
  73. ࣗ࡞ΞϓϦͰͷ$SBTIMZUJDTରࡦ w $SBTIMZUJDTૄ௨ςετ͚࣌ͩ4FUUJOHͷ#6(@*/'03."5*0/@'03."5 ͷ%FCVHΛ%8"3'XJUIE4:.'JMF༗ޮԽ w ૄ௨ςετޙ͸9DPEFઃఆʹ໭͢ w 3VO4DSJQUҰ෦मਖ਼

  74. %&#6(Ҏ֎ͷ࣌ E4:.ϑΝΠϧΛίϐʔ

  75. ·ͱΊ w 'JSFCBTFͷॳखʹ͍ͭͯ·ͱΊ·ͨ͠ w 'JSFCBTF͕4XJGU1BDLBHF.BOBHFS͔Β௥ՃՄೳʹ w σʔλετΞ $MPVE'JSFTUPSF ͷ4XJGU͔Βͷརศੑ޲্͠·ͨ͠

  76. IUUQTJSJNBTVDPN <13>#MPHਵ࣌౤ߘத

  77. ࢀߟ w 4XJGU6*4JHO*O8JUI"QQMFVTJOH'JSFCBTF"VUIc#FUUFS1SPHSBNNJOH w IUUQTCFUUFSQSPHSBNNJOHQVCTJHOJOXJUIBQQMF fi SFCBTFBVUITXJGUVJFGFB w .BQQJOH'JSFTUPSF%BUBJO4XJGUŠ5IF$PNQSFIFOTJWF(VJEFcCZ1FUFS'SJFTFc'JSFCBTF %FWFMPQFSTc"QS

    c.FEJVN w IUUQTNFEJVNDPN fi SFCBTFEFWFMPQFSTNBQQJOH fi SFTUPSFEBUBJOTXJGUUIF DPNQSFIFOTJWFHVJEFBEGC w (JU)VC fi SFCBTFGVODUJPOTTBNQMFT$PMMFDUJPOPGTBNQMFBQQTTIPXDBTJOHQPQVMBSVTF DBTFTVTJOH$MPVE'VODUJPOTGPS'JSFCBTF w IUUQTHJUIVCDPN fi SFCBTFGVODUJPOTTBNQMFT