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
460
Firebaseでつくるグループチェックリスト管理サービス / check list apps on firebase
mogaming
5
540
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
8.1k
Other Decks in Programming
See All in Programming
20年もののレガシープロダクトに 0からPHPStanを入れるまで / phpcon2024
hirobe1999
0
460
プロダクトの品質に コミットする / Commit to Product Quality
pekepek
2
770
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
130
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
1
230
Recoilを剥がしている話
kirik
5
6.6k
Security_for_introducing_eBPF
kentatada
0
110
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
330
testcontainers のススメ
sgash708
1
120
たのしいparse.y
ydah
3
120
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
Go の GC の不得意な部分を克服したい
taiyow
2
770
선언형 UI에서의 상태관리
l2hyunwoo
0
160
Featured
See All Featured
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Building Your Own Lightsaber
phodgson
103
6.1k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
4 Signs Your Business is Dying
shpigford
181
21k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Practical Orchestrator
shlominoach
186
10k
A designer walks into a library…
pauljervisheath
204
24k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
How to Think Like a Performance Engineer
csswizardry
22
1.2k
Adopting Sorbet at Scale
ufuk
73
9.1k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
YesSQL, Process and Tooling at Scale
rocio
169
14k
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 ࠓޙͷΞοϓσʔτʹظͰ͖ΔͷͰΨγΨγ ͍͖͍ͬͯͨ♻