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

Firebase for iOS 初手〇〇

Firebase for iOS 初手〇〇

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

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

notoroid

May 25, 2021
Tweet

More Decks by notoroid

Other Decks in Programming

Transcript

  1. ॆిใࠂ͞Μ #BUUFSFDFJWFS w όοςϦʔϞχλʔ ϢʔςΟϦςΟʔ  w ࠷େ୆ ࣮ػ ϦϞʔτ୆

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

    w ҎԼʹࢦఆ͢Δ͜ͱͰόοςϦʔΛέ Ξ͢Δ͜ͱ͕Մೳ w Կ͔ͱߴ͍J1IPOFΛ௕࣋ͪͤ͞Δͷʹ༗༻
  3. 'JSFCBTFͱ͸ w (PPHMF͕ఏڙ͢ΔϞόΠϧΞϓϦ༻N#BB4 ͷϒϥϯυ w 'JSFCBTFͱ͍͏ϦΞϧλΠϜσʔλϕʔ εͷઌۦ͚ͷϕϯνϟʔΛങऩ w ͦͷ··ϒϥϯυͱͯ͠࢖༻ w

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

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

    ʙ$MPVE'JSFTUPSF ϦΞϧλΠϜσʔλϕʔε ʙ)PTUJOH ϗεςΟϯάαʔϏε ʙ"QQ%JTUSJCVUJPO ݕূΞϓϦͷ഑෍ ʙ4UPSBHF ετϨʔδαʔϏε ʙ3FBMUJNF%BUBCBTF ϦΞϧλΠϜσʔλϕʔε ถࠃͷΈ ๛෋ͳػೳͱ͙͢࢖͑Δརศੑ
  6. 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") } } }
  7. 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
  8. 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") } } } σʔλఆٛ
  9. 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") } } } σʔλΛ௥Ճ͢Δ
  10. 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
  11. 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 ͜ͷൣғΛͳΜͱ͔͍ͨ͠
  12. # 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
  13. # 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ू༻ σʔλετΞ༻ ϓογϡ௨஌༻
  14. "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() } } }
  15. "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
  16. ࢀߟ 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