Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
FirebaseでつくるiOSアプリ/make iOS App with Firebase
Search
mogaming
April 10, 2019
Programming
6
3.5k
FirebaseでつくるiOSアプリ/make iOS App with Firebase
Otemachi.swift #03で発表した資料になります。
mogaming
April 10, 2019
Tweet
Share
More Decks by mogaming
See All by mogaming
Android Instant App 事例調査 / Android Instant App Stories
mogaming
0
450
Firebaseでつくるグループチェックリスト管理サービス / check list apps on firebase
mogaming
5
530
iOSアプリ開発におけるデバイス選択 / Appropriate choise of supporting devices on iOS app development
mogaming
1
1.1k
iOS × GraphQLの嬉しみとツラミ / Pros and cons of iOS and GraphQL
mogaming
4
14k
デザインに込められたエモを知りたい/Emotion in Service Design
mogaming
1
8k
Other Decks in Programming
See All in Programming
Jakarta EE meets AI
ivargrimstad
0
690
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
3
700
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
340
CSC509 Lecture 09
javiergs
PRO
0
140
cmp.Or に感動した
otakakot
3
210
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.3k
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
110
Jakarta EE meets AI
ivargrimstad
0
160
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
110
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
340
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
Featured
See All Featured
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Designing for humans not robots
tammielis
250
25k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
110
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Designing Experiences People Love
moore
138
23k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
Scaling GitHub
holman
458
140k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
430
Transcript
'JSFCBTFͰͭ͘ΔJ04ΞϓϦ 0UFNBDIJTXJGU !@NPHBNJOH
͜ͷࢿྉʹ͍ͭͯ ձʹ߹ΘͤͯɿͰ࡞͍ͬͯ·͢
w !@NPHBNJOHŹŜƄŶƃ w "QQMJDBUJPO&OHJOFFS!%F/" J04 4XJGU "OESPJE ,PUMJO
3BJMT5ZQF4DSJQU(SBQI2- 'JSFCBTF ($1 "84 w αʔϏε࡞Δͷେ͖ "CPVU.F
'JSFCBTF 'JSFCBTFͬͯ·͔͢
'JSFCBTFͱ Πϯϑϥཧෆཁͳ .PCJMF#BDLFOEBTB4FSWJDF N#BB4
'JSFCBTFͱ ӡ༻අΛ͋·Γ͔͚ͣʹ όοΫΤϯυͰΓ͍ͨ͜ͱ͕ ͍͍ͩͨͰ͖Δศརͳͭ ένͳ΅͘ʻ
'JSFCBTF Կ͕Ͱ͖Δͷʁ
w ೝূʢ"VUIFOUJDBUJPOʣ w σʔλอଘʢ'JSFTUPSFʣ w 8FC"1*'BB4ʢ$MPVE'VODUJPOTʣ w ϓογϡ௨ʢ$MPVE.FTTBHJOHʣ w 6OJWFSTBM-JOLTʢ%ZOBNJD-JOLTʣ
'JSFCBTFͰͰ͖Δ͜ͱʢҰ෦ʣ ͳͲͳͲ
'JSFCBTFͷ׆༻ࣄྫ ࣮ࡍʹ'JSFCBTFΛ׆༻͍ͯ͠Δ αʔϏε͕͍͟͝·ͯ͠ʜ
֣։֥֍ EJGEMC ෳਓͰڞ༗Ͱ͖Δ νΣοΫϦετΞϓϦ
ՈͰʂ ίϛϡχέʔγϣϯ ϥΫϥΫʂ
DIFDLBͷը໘આ໌ νΣοΫϦετͷάϧʔϐϯά νΣοΫϦετ
DIFDLB ͜ͷΞϓϦͰͷར༻ํ๏ࠞ͑ͯ͡ 'JSFCBTFΛͲͷΑ͏ʹ׆༻ͯ͠ ΞϓϦΛ࡞͍ͬͯ͘ͷ͔Λ͓͠·͢
σʔλอଘʢ'JSFTUPSFʣ ೝূʢ"VUIFOUJDBUJPOʣ ࠓճհ͢Δػೳ
ಋೖ
ಋೖํ๏ $PDPB1PETʹΑΔཧ pod 'Firebase/Core'
4%,ͷॳظԽ import Firebase FirebaseApp.configure()
σʔλอଘ 'JSFCBTF'JSFTUPSF
ಋೖํ๏ pod 'Firebase/Firestore'
w /P42-σʔλϕʔε εΩʔϚϨε .POHP%# %ZOBNP%#ͳͲ w ؆୯ͳΫΤϦɺτϥϯβΫγϣϯ͕͑Δ w
εέʔϥϒϧɺίετ 3FBE8SJUFͷྔʹԠͯ͡՝ۚ ݅ಡΈऔΓͰ͘Β͍ʢ ݅ແྉʣ 'JSFCBTF'JSFTUPSFͱ https://firebase.google.com/docs/firestore/?hl=ja
$PMMFDUJPOͱ%PDVNFOU w $PMMFDUJPO 3%#Ͱ͍͏5BCMF ҙͷͷ%PDVNFOUΛ࣋ͭ w
%PDVNFOU 3%#Ͱ͍͏3FDPSE $PMMFDUJPOʹඞͣଐ͢Δ
'JSFTUPSFͷσʔλߏ ڊେͳͭͷ+40/͕ͭͷ%BUBCBTF Έ͍ͨͳΠϝʔδ
+40/ͷΠϝʔδ { "users": { "user1": { "name": "͕",
"posts": { "post1": { "title": "ݽߴͷiOSΤϯδχΞ" } } }, "user2": { "name": "Ί͕Ͷ", "posts": { "post1": { "title": "ਖ਼͍͠ϝΨωͷ১͖ํ" } } } } } υΩϡϝϯτ ίϨΫγϣϯ
'JSFTUPSFͷॻ͖ࠐΈ import FirebaseFirestore Firestore.firestore() .collection("users") // ίϨΫγϣϯ໊ .document()
// υΩϡϝϯτ .setData(["name": "moga"]) { error in // error handling }
'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]] }
'JSFTUPSFͷϦΞϧλΠϜมߋ௨ import FirebaseFirestore Firestore.firestore() .collection("users") .addSnapshotListener { snapshot,
error in let users = snapshot!.documents.map { $0.data() } // มߋ͕͋ΔͨͼʹݺΕΔ } DIFDLBͰ͜͜Ͱड͚औͬͨ༰Λ ࠩߋ৽ϥΠϒϥϦʹͿΜ͍͛ͯ·͢
σʔλߏྫ #PBSE 5BTL (SPVQ
σʔλߏྫɿ3%# Groups Boards Tasks σʔλ֊ฒྻ 5BCMF 5BCMF 5BCMF
+0*/ +0*/
w 'JSFTUPSF্Ͱͷ+0*/͕Ͱ͖ͳ͍ $MJFOU4JEF+PJO·ͨ3FBE༻σʔλͷ༻ҙͰରԠ͢Δ ʢ/P42-ͦ͏͍͏ͷʣ w σʔλߏͷઃܭʹ׳Ε͕ඞཁ 3%#ͷৗࣺࣝͯΔඞཁ͕͋Δ
w ΫΤϦ੍͕ݶ͞Ε͍ͯΔ 03͕͑ͳ͍ɺ͕͑ͳ͍ 'JSFTUPSFͰҙ͍ͨ͜͠ͱ
σʔλߏྫɿ'JSFTUPSF Group1 Board1 Task1 σʔλ֊ʹࢠؔΛͨͤΔ 3%#.4ͷΑ͏ʹߏΛฒྻʹ͢Δ͜ͱͰ͖Δ͕ σʔλ3FBEͷύϑΥʔϚϯεͱηΩϡϦςΟతʹΒͳ͍΄͏͕Αͦ͞͏ Board2
Task2 Task3 Task4 Task5 Task6 (SPVQT #PBSET 5BTLT
ͳͥࢠؔΛͨͤΔͷ͔ ͳͥࢠؔΛͨͤΔඞཁ͕͋Δͷ͔
ͳͥࢠؔΛͨͤΔͷ͔ 'JSFTUPSFͷσʔλΞΫηεࢥ ηΩϡϦςΟཁ݅ͷ࣮ݱ
'JSFTUPSFͷࢥ iOS App WebServer Database ैདྷͷΞϓϦέʔγϣϯ iOS App
Firestore 'JSFTUPSFͷࢥ ΫϥΠΞϯτ͕σʔλͷಡΈॻ͖Λ͢Δ
'JSFTUPSFͷࢥͷΑ͞ 'JSFTUPSFͷࢥʹϝϦοτ͋Δͷ͔
'JSFTUPSFͷࢥͷΑ͞ %#ͷಡΈॻ͖ॲཧΛΞϓϦଆͰ݁Ͱ͖Δ όοΫΤϯυͷ࣮͕΄΅ෆཁʂ
ͳʹ͕خ͍͠ ຊʹ࣮εϐʔυ͕͕͋Γ·͢
͍͍͍͍ ⚠ͪΐͬͱͬͨ⚠
ΫϥΠΞϯτ͕%#Λ৮Δʜʁ ΫϥΠΞϯτ͕ %#Λ৮ΔͳΜͯةݥͰ ŦŘŴŖ
ΫϥΠΞϯτ͕%#Λ৮Δʜʁ ηΩϡϦςΟϧʔϧͱ͍͏ͷ͕͋Γ·͢ https://firebase.google.com/docs/firestore/security/overview?hl=ja
ηΩϡϦςΟϧʔϧͱ w σʔλͷΞΫηεݖݶΛهड़͢Δ SFBE HFUMJTU XSJUF DSFBUFVQEBUFEFMFUF
w +BWB4DSJQUΈ͍ͨͳಠࣗݴޠΛ͏
σʔλߏྫɿ'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,ͷྫ
σʔλߏྫɿ'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ʹઃఆ͓͚ͯ͠ ҙਤ͠ͳ͍ಡΈॻ͖Λ੍ޚ͢Δ͜ͱ͕Ͱ͖Δ
'JSFTUPSFͷҙ w σʔλߏͷઃܭ׳ΕΔ·Ͱຊʹ͍͠ αʔϏεཁ݅ʹ߹ΘͤΔඞཁ͕͋Δ w ࠓճհͰ͖͍ͯͳ͍ςΫχοΫΛ͏ඞཁ͕͋Δ ߹Ͱͯ͘Δ
ಡΈऔΓ༻σʔλͷ࡞ w ΅͘Ͱྑ͚Ε͍ͭͰ5XJUUFS͔Β͝૬ஊ͍ͩ͘͞ ͓ࣄͷґཔ͓͍ͪͯ͠·͢,
'JSFTUPSFͰࢀߟʹͳΔ63- w ެࣜυΩϡϝϯτ IUUQTpSFCBTFHPPHMFDPNEPDTpSFTUPSF IMKB 'JSFCBTFެࣜυΩϡϝϯτ͕݁ߏॆ࣮͍ͯ͠·͢
w $MPVE'JSFTUPSFͷצॴύʔτ IUUQTNFEJVNDPNHPPHMFDMPVEKQpSFTUPSFBBDE ΊͪΌͪ͘ΌΘ͔Γ͘͢ɺશମײؾΛ͚ͭΔ͖ͱ͜Ζ͕ѲͰ͖ ·͢ɻࣗԿճಡΈ·ͨ͠ɻ
ೝূ 'JSFCBTF"VUIFOUJDBUJPO
ಋೖํ๏ pod 'Firebase/Auth'
'JSFCBTF"VUIFOUJDBUJPOͱ ϢʔβʔೝূαʔϏε https://firebase.google.com/docs/auth/?hl=ja
w ಗ໊ೝূ w ϝʔϧΞυϨεೝূ w ి൪߸ೝূ w 4/4ೝূʢ(PPHMF'BDFCPPL5XJUUFS(JU)VCʣ w ΧελϜೝূ
"VUIFOUJDBUJPOͷೝূखஈ
w ։ൃऀ͕6*Λ࣮͠ඞཁͳใΛ4%,ʹΘͨ͢ w 6*4%,ΒͤΔ "VUIFOUJDBUJPOͷ࣮खஈ
"VUIFOUJDBUJPO؆୯ ͲΕ؆୯ʹར༻͢Δ͜ͱ͕Ͱ͖·͢ ʢ֤4/4αʔϏεͰඞཁͳઃఆΛ͢Δ΄͏͕ΊΜͲ͍͘͞ʣ
DIFDLBͰ DIFDLBͰಗ໊ೝূΛ͍ͬͯ·͢ ʑ4/4ೝূಋೖ༧ఆͰ͕͢ݱঢ়े
ಗ໊ೝূ import FirebaseAuth Auth.auth().signInAnonymously { result, error in
print(result?.user.uid) } ΞϓϦΛΞϯΠϯετʔϧ͢ΔͳͲ͠ͳ͍ݶΓಉ͡6TFSʹͳΔ ʢυΩϡϝϯτ͕͋ͬͨͣͳΜͰ͕͢ݟͨΒͣʜʣ
·ͱΊ w 'JSFCBTFͱͬͯศར w 'JSFTUPSFʹଟগͷ׳Ε͕ඞཁ͕ͩඇৗʹڧྗ☄ w ࠓޙͷΞοϓσʔτʹظͰ͖ΔͷͰΨγΨγ ͍͖͍ͬͯͨ♻