FirebaseでつくるiOSアプリ/make iOS App with Firebase

21807122e5564f4775b813d2eb17efaf?s=47 mogaming
April 10, 2019

FirebaseでつくるiOSアプリ/make iOS App with Firebase

Otemachi.swift #03で発表した資料になります。

21807122e5564f4775b813d2eb17efaf?s=128

mogaming

April 10, 2019
Tweet

Transcript

  1. 'JSFCBTFͰͭ͘ΔJ04ΞϓϦ 0UFNBDIJTXJGU !@NPHBNJOH

  2.   ͜ͷࢿྉʹ͍ͭͯ ձ৔ʹ߹ΘͤͯɿͰ࡞͍ͬͯ·͢

  3. w !@NPHBNJOHŹŜƄŶƃ w "QQMJDBUJPO&OHJOFFS!%F/"  J04 4XJGU "OESPJE ,PUMJO 

     3BJMT5ZQF4DSJQU(SBQI2-  'JSFCBTF ($1 "84 w αʔϏε࡞Δͷେ޷͖   "CPVU.F
  4.   'JSFCBTF 'JSFCBTF࢖ͬͯ·͔͢

  5.   'JSFCBTFͱ͸ Πϯϑϥ؅ཧෆཁͳ .PCJMF#BDLFOEBTB4FSWJDF N#BB4

  6.   'JSFCBTFͱ͸ ӡ༻අΛ͋·Γ͔͚ͣʹ όοΫΤϯυͰ΍Γ͍ͨ͜ͱ͕ ͍͍ͩͨͰ͖Δศརͳ΍ͭ ένͳ΅͘ʻ

  7.   'JSFCBTF Կ͕Ͱ͖Δͷʁ

  8. w ೝূʢ"VUIFOUJDBUJPOʣ w σʔλอଘʢ'JSFTUPSFʣ w 8FC"1*'BB4ʢ$MPVE'VODUJPOTʣ w ϓογϡ௨஌ʢ$MPVE.FTTBHJOHʣ w 6OJWFSTBM-JOLTʢ%ZOBNJD-JOLTʣ

      'JSFCBTFͰͰ͖Δ͜ͱʢҰ෦ʣ ͳͲͳͲ
  9.   'JSFCBTFͷ׆༻ࣄྫ ࣮ࡍʹ'JSFCBTFΛ׆༻͍ͯ͠Δ αʔϏε͕͍͟͝·ͯ͠ʜ

  10. ֣։֥֍ EJGEMC ෳ਺ਓͰڞ༗Ͱ͖Δ νΣοΫϦετΞϓϦ

  11. Ո଒Ͱʂ ίϛϡχέʔγϣϯ΋ ϥΫϥΫʂ

  12.   DIFDLBͷը໘આ໌ νΣοΫϦετͷάϧʔϐϯά νΣοΫϦετ

  13.   DIFDLB ͜ͷΞϓϦͰͷར༻ํ๏΋ࠞ͑ͯ͡ 'JSFCBTFΛͲͷΑ͏ʹ׆༻ͯ͠ ΞϓϦΛ࡞͍ͬͯ͘ͷ͔Λ͓࿩͠·͢

  14.  σʔλอଘʢ'JSFTUPSFʣ  ೝূʢ"VUIFOUJDBUJPOʣ   ࠓճ঺հ͢Δػೳ

  15. ಋೖ

  16.   ಋೖํ๏ $PDPB1PETʹΑΔ؅ཧ pod 'Firebase/Core'

  17.   4%,ͷॳظԽ import Firebase FirebaseApp.configure()

  18. σʔλอଘ 'JSFCBTF'JSFTUPSF

  19.   ಋೖํ๏ pod 'Firebase/Firestore'

  20. w /P42-σʔλϕʔε  εΩʔϚϨε  .POHP%# %ZOBNP%#ͳͲ w ؆୯ͳΫΤϦɺτϥϯβΫγϣϯ͕࢖͑Δ w

    εέʔϥϒϧɺ௿ίετ  3FBE8SJUFͷྔʹԠͯ͡՝ۚ   ݅ಡΈऔΓͰ͘Β͍ʢ ݅೔͸ແྉʣ   'JSFCBTF'JSFTUPSFͱ͸ https://firebase.google.com/docs/firestore/?hl=ja
  21.   $PMMFDUJPOͱ%PDVNFOU w $PMMFDUJPO  3%#Ͱ͍͏5BCMF  ೚ҙͷ਺ͷ%PDVNFOUΛ࣋ͭ w

    %PDVNFOU  3%#Ͱ͍͏3FDPSE  $PMMFDUJPOʹඞͣଐ͢Δ
  22.   'JSFTUPSFͷσʔλߏ଄ ڊେͳͭͷ+40/͕ͭͷ%BUBCBTF Έ͍ͨͳΠϝʔδ

  23.   +40/ͷΠϝʔδ { "users": { "user1": { "name": "΋͕",

    "posts": { "post1": { "title": "ݽߴͷiOSΤϯδχΞ" } } }, "user2": { "name": "Ί͕Ͷ", "posts": { "post1": { "title": "ਖ਼͍͠ϝΨωͷ১͖ํ" } } } } } υΩϡϝϯτ ίϨΫγϣϯ
  24.   'JSFTUPSF΁ͷॻ͖ࠐΈ import FirebaseFirestore Firestore.firestore() .collection("users") // ίϨΫγϣϯ໊ .document()

    // υΩϡϝϯτ .setData(["name": "moga"]) { error in // error handling }
  25.   'JSFTUPSF͔ΒͷίϨΫγϣϯಡΈऔΓ import FirebaseFirestore Firestore.firestore() .collection("users") .whereField("age", isEqualTo: 20)

    // where .getDocuments { snapshot, error in let users = snapshot!.documents.map { $0.data() } users // ϢʔβʔҰཡऔಘ [[String: Any]] }
  26.   'JSFTUPSF΁ͷϦΞϧλΠϜมߋ௨஌ import FirebaseFirestore Firestore.firestore() .collection("users") .addSnapshotListener { snapshot,

    error in let users = snapshot!.documents.map { $0.data() } // มߋ͕͋Δͨͼʹݺ͹ΕΔ } DIFDLBͰ͸͜͜Ͱड͚औͬͨ಺༰Λ ࠩ෼ߋ৽ϥΠϒϥϦʹͿΜ౤͍͛ͯ·͢
  27. σʔλߏ଄ྫ #PBSE 5BTL (SPVQ

  28.   σʔλߏ଄ྫɿ3%# Groups Boards Tasks σʔλ֊૚͸ฒྻ 5BCMF 5BCMF 5BCMF

    +0*/ +0*/
  29. w 'JSFTUPSF্Ͱͷ+0*/͕Ͱ͖ͳ͍  $MJFOU4JEF+PJO·ͨ͸3FBE༻σʔλͷ༻ҙͰରԠ͢Δ  ʢ/P42-͸ͦ͏͍͏΋ͷʣ w σʔλߏ଄ͷઃܭʹ׳Ε͕ඞཁ  3%#ͷৗࣝ͸ࣺͯΔඞཁ͕͋Δ

    w ΫΤϦ੍͕ݶ͞Ε͍ͯΔ  03͕࢖͑ͳ͍ɺ͕࢖͑ͳ͍   'JSFTUPSFͰ஫ҙ͍ͨ͜͠ͱ
  30.   σʔλߏ଄ྫɿ'JSFTUPSF Group1 Board1 Task1 σʔλ֊૚ʹ͸਌ࢠؔ܎Λ΋ͨͤΔ 3%#.4ͷΑ͏ʹߏ଄Λฒྻʹ͢Δ͜ͱ΋Ͱ͖Δ͕ σʔλ3FBEͷύϑΥʔϚϯεͱηΩϡϦςΟతʹ΍Βͳ͍΄͏͕Αͦ͞͏ Board2

    Task2 Task3 Task4 Task5 Task6 (SPVQT #PBSET 5BTLT
  31.   ͳͥ਌ࢠؔ܎Λ΋ͨͤΔͷ͔ ͳͥ਌ࢠؔ܎Λ΋ͨͤΔඞཁ͕͋Δͷ͔

  32.   ͳͥ਌ࢠؔ܎Λ΋ͨͤΔͷ͔  'JSFTUPSFͷσʔλΞΫηεࢥ૝  ηΩϡϦςΟཁ݅ͷ࣮ݱ

  33.   'JSFTUPSFͷࢥ૝ iOS App WebServer Database ैདྷͷΞϓϦέʔγϣϯ iOS App

    Firestore 'JSFTUPSFͷࢥ૝ ΫϥΠΞϯτ͕௚઀σʔλͷಡΈॻ͖Λ͢Δ
  34.   'JSFTUPSFͷࢥ૝ͷΑ͞ 'JSFTUPSFͷࢥ૝ʹϝϦοτ͸͋Δͷ͔

  35.   'JSFTUPSFͷࢥ૝ͷΑ͞ %#ͷಡΈॻ͖ॲཧΛΞϓϦଆͰ׬݁Ͱ͖Δ όοΫΤϯυͷ࣮૷͕΄΅ෆཁʂ

  36.   ͳʹ͕خ͍͠ ຊ౰ʹ࣮૷εϐʔυ͕͕͋Γ·͢

  37.   ͍΍͍΍͍΍͍΍ ⚠ͪΐͬͱ଴ͬͨ⚠

  38.   ΫϥΠΞϯτ͕௚઀%#Λ৮Δʜʁ ΫϥΠΞϯτ͕
 %#Λ௚઀৮ΔͳΜͯةݥͰ͸ ŦŘŴŖ

  39.   ΫϥΠΞϯτ͕௚઀%#Λ৮Δʜʁ ηΩϡϦςΟϧʔϧͱ͍͏΋ͷ͕͋Γ·͢ https://firebase.google.com/docs/firestore/security/overview?hl=ja

  40.   ηΩϡϦςΟϧʔϧͱ͸ w σʔλͷΞΫηεݖݶΛهड़͢Δ  SFBE HFUMJTU XSJUF DSFBUFVQEBUFEFMFUF

     w +BWB4DSJQUΈ͍ͨͳಠࣗݴޠΛ࢖͏
  41.   σʔλߏ଄ྫɿ'JSFTUPSF service cloud.firestore { match /databases/{database}/documents { match

    /users/{userID} { // {userID}͸PathParameterΈ͍ͨͳ΋ͷ allow get, list; // ୭Ͱ΋ಡΈऔΓՄ allow create, update: if request.auth != null // ೝূࡁΈϢʔβʔ && request.auth.uid == userID // ϦΫΤετϢʔβʔͱσʔλ͕Ұக } } } σʔλߏ଄্ͷҐஔ ແ৚݅ʹಡΈऔΓڐՄ ࣗ਎ͷσʔλͷΈมߋՄ ϓϩϑΟʔϧ͸୭Ͱ΋ݟ͍͍͚ͯͲฤू͸ࣗ෼ͷΈ0,ͷྫ
  42.   σʔλߏ଄ྫɿ'JSFTUPSF service cloud.firestore { match /databases/{database}/documents { match

    /users/{userID} { // {userID}͸QueryParameterΈ͍ͨͳ΋ͷ allow get, list; // ୭Ͱ΋ಡΈऔΓՄ allow create, update: if request.auth != null // ೝূࡁΈϢʔβʔ && request.auth.uid == userID // ϦΫΤετϢʔβʔͱσʔλ͕Ұக } } } ͜ΕΛ'JSFTUPSFʹઃఆ͓͚ͯ͠͹ ҙਤ͠ͳ͍ಡΈॻ͖Λ੍ޚ͢Δ͜ͱ͕Ͱ͖Δ
  43.   'JSFTUPSFͷ஫ҙ఺ w σʔλߏ଄ͷઃܭ͸׳ΕΔ·Ͱຊ౰ʹ೉͍͠  αʔϏεཁ݅ʹ߹ΘͤΔඞཁ͕͋Δ w ࠓճ঺հͰ͖͍ͯͳ͍ςΫχοΫΛ࢖͏ඞཁ͕͋Δ ৔߹΋Ͱͯ͘Δ

     ಡΈऔΓ༻σʔλͷ࡞੒ w ΅͘Ͱྑ͚Ε͹͍ͭͰ΋5XJUUFS͔Β͝૬ஊ͍ͩ͘͞  ͓࢓ࣄͷґཔ΋͓଴͍ͪͯ͠·͢,
  44.   'JSFTUPSFͰࢀߟʹͳΔ63- w ެࣜυΩϡϝϯτ  IUUQTpSFCBTFHPPHMFDPNEPDTpSFTUPSF IMKB  'JSFCBTF͸ެࣜυΩϡϝϯτ͕݁ߏॆ࣮͍ͯ͠·͢

    w $MPVE'JSFTUPSFͷצॴύʔτ  IUUQTNFEJVNDPNHPPHMFDMPVEKQpSFTUPSFBBDE  ΊͪΌͪ͘ΌΘ͔Γ΍͘͢ɺશମײ΍ؾΛ͚ͭΔ΂͖ͱ͜Ζ͕೺ѲͰ͖ ·͢ɻࣗ෼͸Կճ΋ಡΈ·ͨ͠ɻ
  45. ೝূ 'JSFCBTF"VUIFOUJDBUJPO

  46.   ಋೖํ๏ pod 'Firebase/Auth'

  47.   'JSFCBTF"VUIFOUJDBUJPOͱ͸ ϢʔβʔೝূαʔϏε https://firebase.google.com/docs/auth/?hl=ja

  48. w ಗ໊ೝূ w ϝʔϧΞυϨεೝূ w ి࿩൪߸ೝূ w 4/4ೝূʢ(PPHMF'BDFCPPL5XJUUFS(JU)VCʣ w ΧελϜೝূ

      "VUIFOUJDBUJPOͷೝূखஈ
  49. w ։ൃऀ͕6*Λ࣮૷͠ඞཁͳ৘ใΛ4%,ʹΘͨ͢ w 6*΋4%,΍ΒͤΔ   "VUIFOUJDBUJPOͷ࣮૷खஈ

  50.   "VUIFOUJDBUJPO͸؆୯ ͲΕ΋؆୯ʹར༻͢Δ͜ͱ͕Ͱ͖·͢ ʢ֤4/4αʔϏεͰඞཁͳઃఆΛ͢Δ΄͏͕ΊΜͲ͍͘͞ʣ

  51.   DIFDLBͰ͸ DIFDLBͰ͸ಗ໊ೝূΛ࢖͍ͬͯ·͢ ௥ʑ4/4ೝূ΋ಋೖ༧ఆͰ͕͢ݱঢ়͸े෼

  52.   ಗ໊ೝূ import FirebaseAuth Auth.auth().signInAnonymously { result, error in

    print(result?.user.uid) } ΞϓϦΛΞϯΠϯετʔϧ͢ΔͳͲ͠ͳ͍ݶΓ͸ಉ͡6TFSʹͳΔ ʢυΩϡϝϯτ͕͋ͬͨ͸ͣͳΜͰ͕͢ݟ౰ͨΒͣʜʣ
  53.   ·ͱΊ w 'JSFCBTF͸ͱͬͯ΋ศར w 'JSFTUPSFʹ͸ଟগͷ׳Ε͕ඞཁ͕ͩඇৗʹڧྗ☄ w ࠓޙͷΞοϓσʔτʹ΋ظ଴Ͱ͖ΔͷͰΨγΨγ
 ࢖͍͖͍ͬͯͨ♻