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

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

mogaming
April 10, 2019

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

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

mogaming

April 10, 2019
Tweet

More Decks by mogaming

Other Decks in Programming

Transcript

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

     3BJMT5ZQF4DSJQU(SBQI2-  'JSFCBTF ($1 "84 w αʔϏε࡞Δͷେ޷͖   "CPVU.F
  2. w /P42-σʔλϕʔε  εΩʔϚϨε  .POHP%# %ZOBNP%#ͳͲ w ؆୯ͳΫΤϦɺτϥϯβΫγϣϯ͕࢖͑Δ w

    εέʔϥϒϧɺ௿ίετ  3FBE8SJUFͷྔʹԠͯ͡՝ۚ   ݅ಡΈऔΓͰ͘Β͍ʢ ݅೔͸ແྉʣ   'JSFCBTF'JSFTUPSFͱ͸ https://firebase.google.com/docs/firestore/?hl=ja
  3.   +40/ͷΠϝʔδ { "users": { "user1": { "name": "΋͕",

    "posts": { "post1": { "title": "ݽߴͷiOSΤϯδχΞ" } } }, "user2": { "name": "Ί͕Ͷ", "posts": { "post1": { "title": "ਖ਼͍͠ϝΨωͷ১͖ํ" } } } } } υΩϡϝϯτ ίϨΫγϣϯ
  4.   '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]] }
  5.   'JSFTUPSF΁ͷϦΞϧλΠϜมߋ௨஌ import FirebaseFirestore Firestore.firestore() .collection("users") .addSnapshotListener { snapshot,

    error in let users = snapshot!.documents.map { $0.data() } // มߋ͕͋Δͨͼʹݺ͹ΕΔ } DIFDLBͰ͸͜͜Ͱड͚औͬͨ಺༰Λ ࠩ෼ߋ৽ϥΠϒϥϦʹͿΜ౤͍͛ͯ·͢
  6.   'JSFTUPSFͷࢥ૝ iOS App WebServer Database ैདྷͷΞϓϦέʔγϣϯ iOS App

    Firestore 'JSFTUPSFͷࢥ૝ ΫϥΠΞϯτ͕௚઀σʔλͷಡΈॻ͖Λ͢Δ
  7.   σʔλߏ଄ྫɿ'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,ͷྫ
  8.   σʔλߏ଄ྫɿ'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ʹઃఆ͓͚ͯ͠͹ ҙਤ͠ͳ͍ಡΈॻ͖Λ੍ޚ͢Δ͜ͱ͕Ͱ͖Δ
  9.   'JSFTUPSFͷ஫ҙ఺ w σʔλߏ଄ͷઃܭ͸׳ΕΔ·Ͱຊ౰ʹ೉͍͠  αʔϏεཁ݅ʹ߹ΘͤΔඞཁ͕͋Δ w ࠓճ঺հͰ͖͍ͯͳ͍ςΫχοΫΛ࢖͏ඞཁ͕͋Δ ৔߹΋Ͱͯ͘Δ

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

    w $MPVE'JSFTUPSFͷצॴύʔτ  IUUQTNFEJVNDPNHPPHMFDMPVEKQpSFTUPSFBBDE  ΊͪΌͪ͘ΌΘ͔Γ΍͘͢ɺશମײ΍ؾΛ͚ͭΔ΂͖ͱ͜Ζ͕೺ѲͰ͖ ·͢ɻࣗ෼͸Կճ΋ಡΈ·ͨ͠ɻ
  11.   ಗ໊ೝূ import FirebaseAuth Auth.auth().signInAnonymously { result, error in

    print(result?.user.uid) } ΞϓϦΛΞϯΠϯετʔϧ͢ΔͳͲ͠ͳ͍ݶΓ͸ಉ͡6TFSʹͳΔ ʢυΩϡϝϯτ͕͋ͬͨ͸ͣͳΜͰ͕͢ݟ౰ͨΒͣʜʣ