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. 'JSFCBTFGPSJ04
    ॳखʓʓ

    View full-size slide

  2. ೳొཁ !OPUPSPJE

    w J04ΞϓϦ։ൃऀ
    w ԰߸͍Γ·͢ిࢉاը
    w !OPUPSPJE
    w !JSJNBTV
    w ࠷ۙͷಈ޲
    w ϒϩά࡮৽͠·ͨ͠

    View full-size slide

  3. ॆిใࠂ͞Μ #BUUFSFDFJWFS

    w όοςϦʔϞχλʔ ϢʔςΟϦςΟʔ

    w ࠷େ୆ ࣮ػϦϞʔτ୆

    w ख࣋ͪͷJ1IPOF͔Βଞʹ͍࣋ͬͯΔ
    J1IPOF J1BEͳͲͷػثͷόοςϦʔঢ়ଶ֬
    ೝՄೳ
    w ࣗ୐ʹ͋ΔJ1IPOFͷόοςϦʔঢ়ଶ֬ೝՄ

    View full-size slide

  4. ॆిใࠂ͞Μ #BUUFSFDFJWFS

    w "QQMF8BUDIରԠ
    w $PNQMJDBUJPOTରԠ
    w ॆి׬ྃ௨஌
    w ॆి׬ྃΛ఻͑ͯ͘ΕΔ௨஌Λ௥Ճ
    w ҎԼʹࢦఆ͢Δ͜ͱͰόοςϦʔΛέ
    Ξ͢Δ͜ͱ͕Մೳ
    w Կ͔ͱߴ͍J1IPOFΛ௕࣋ͪͤ͞Δͷʹ༗༻

    View full-size slide

  5. ࿩͢͜ͱ
    w 'JSFCBTFͷτϐοΫ
    w ϞόΠϧΞϓϦ։ൃͰͷ'JSFCBTFॳख

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  8. 'JSFCBTF֓ཁ

    View full-size slide

  9. 88%$։࠵ؒۙ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  13. 'JSFCBTFͱ͸

    View full-size slide

  14. 'JSFCBTFͱ͸
    w (PPHMF͕ఏڙ͢ΔϞόΠϧΞϓϦ༻N#BB4
    ͷϒϥϯυ
    w 'JSFCBTFͱ͍͏ϦΞϧλΠϜσʔλϕʔ
    εͷઌۦ͚ͷϕϯνϟʔΛങऩ
    w ͦͷ··ϒϥϯυͱͯ͠࢖༻
    w ଞαʔϏε 'BCSJD
    ΋ٵऩ
    w (PPHMF$MPVEQMBUGPSNΛج൫ʹϞόΠ
    ϧαʔϏεʹదͨ͠ܗͰఏڙ
    w ैྔ՝ۚ੡

    View full-size slide

  15. ϓϥοτϑΥʔϜαʔϏεରԠ
    w ϞόΠϧ޲͚
    w 'JSFCBTFJ044%,
    w 'JSFCBTF"OESPJE4%,
    w 'JSFCBTF+BWBTDSJQU4%, 8FCϑϩϯτΤϯυ޲͚

    w 'JSFCBTF"ENJO4%, αʔόʔαʔόʔϨε޲͚

    ϞόΠϧΞϓϦͱόοΫΤϯυͰͷ'JSFCBTFػೳݺͼग़͠Λαϙʔτ

    View full-size slide

  16. 'JSFCBTFͷػೳ ൈਮ

    ʙ"VUIFOUJDBUJPO Ϣʔβʔೝূ
    ʙ$SBTIMZUJDT Ϋϥογϡ৘ใڞ༗
    ʙ$MPVE.FTTBHJOH ϓογϡ௨஌
    ʙ$MPVE'VODUJPOT αʔόʔϨείϯϐϡʔςΟϯά
    ʙ$MPVE'JSFTUPSF ϦΞϧλΠϜσʔλϕʔε
    ʙ)PTUJOH ϗεςΟϯάαʔϏε
    ʙ"QQ%JTUSJCVUJPO ݕূΞϓϦͷ഑෍
    ʙ4UPSBHF ετϨʔδαʔϏε
    ʙ3FBMUJNF%BUBCBTF ϦΞϧλΠϜσʔλϕʔε ถࠃͷΈ

    ๛෋ͳػೳͱ͙͢࢖͑Δརศੑ

    View full-size slide

  17. ϞόΠϧϓϥοτϑΥʔϜΛαϙʔτ͠
    όοΫΤϯυ΋ରԠ͢ΔαʔϏεʹ੒௕

    View full-size slide

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

    View full-size slide

  19. 'JSFCBTFʹؔ͢Δ࿩୊

    View full-size slide

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

    View full-size slide

  21. 4XJGU1BDLBHF.BOBHFSରԠ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  25. 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")


    }


    }


    }

    View full-size slide

  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")


    }


    }


    }
    ඞཁͳJNQPSU

    View full-size slide

  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")


    }


    }


    }
    σʔλఆٛ

    View full-size slide

  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")


    }


    }


    }
    σʔλΛ௥Ճ͢Δ

    View full-size slide

  29. 'JSFTUPSF΁൓ө

    View full-size slide

  30. 'JSFCBTFॳखʓʓ

    View full-size slide

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

    View full-size slide

  32. ͱ͸ݴͬͯ΋

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  37. ಋೖϞσϧ

    View full-size slide

  38. 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

    View full-size slide

  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
    ͜ͷൣғΛͳΜͱ͔͍ͨ͠

    View full-size slide

  40. ૝ఆΞϓϦ
    ϓϩδΣΫτ໊͸"DUJWJUZ5FTU
    ίʔυྔͷ౎߹্4XJGU6* ͓ͦΒ͘6*,JUɺ'MVUUFSͰ΋աఔมΘΒͳ͍͸ͣ

    લఏ
    'JSFCBTFίϯιʔϧ΁ϩάΠϯՄೳ
    $PDPBQPET࢖༻
    Ϋϥογϡ৘ใΛऩू͢Δ
    ϢʔβʔೝূΛ༗ޮʹ͢Δ "VUIFOUJDBUJPO

    4JHO*OXJUI"QQMF
    'JSFTPSF'JSFTUPSFΛ༗ޮԽ
    ͓஌ΒͤҰཡػೳΛ୲ΘͤΔͨΊͷج൫ͱͯ͠σʔλετΞΛར༻͍ͨ͠

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  43. ·ͣ࠷ॳʹ͢Δ͜ͱ͸

    View full-size slide

  44. ՝ۚϓϥϯͷมߋ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  49. J04ϘλϯΛλοϓ

    View full-size slide

  50. #VOEMF*EFOUJ
    fi
    FSΛೖྗ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  54. # 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


    View full-size slide

  55. # 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ू༻
    σʔλετΞ༻
    ϓογϡ௨஌༻

    View full-size slide

  56. $PDPBQPETΛΠϯετʔϧޙɺ
    ௥Ճ͞ΕͨϫʔΫεϖʔεϑΝΠϧ
    "DUJWJUZ5FTUYDXPSLTQBDF

    Λ։͚͹'JSFCBTFͷಋೖ׬ྃ

    View full-size slide

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

    View full-size slide

  58. αϯϓϧίʔυղઆ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  63. "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()


    }


    }


    }


    View full-size slide

  64. "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

    View full-size slide

  65. "DUJWJUZ5FTU"QQͷίϝϯτΞ΢τ͞Ε
    ͨ7JFXͱ'JSFTUPSFίϯιʔϧͷࢦࣔ௨
    Γʹ͢Ε͹جຊ0,

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  68. $SBTIMZUJDTͱ9DPEFઃఆ
    %FCVH 3FMFBTFઃఆ
    9DPEFͷ΢ΟβʔυͰͷઃఆ
    %(@*/'03."5*0/@'03."5
    %8"3' %8"3'XJUIE4:.'JMF
    $SBTIMZUJDTͷૄ௨ςετ
    ࢖༻༗ແ
    ૄ௨ςετʹ࢖༻͢Δ ૄ௨ςετʹ࢖༻͠ͳ͍
    %8"3'XJUIE4:.'JMF͕
    ඞཁͳͷʹૄ௨ςετʹ࢖༻͢Δ
    %FCVH൛͸ແޮʹͳ͍ͬͯΔ

    View full-size slide

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

    View full-size slide

  70. %(Ҏ֎ͷ࣌
    E4:.ϑΝΠϧΛίϐʔ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  73. ࢀߟ
    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

    View full-size slide