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
440
Firebaseでつくるグループチェックリスト管理サービス / check list apps on firebase
mogaming
5
530
iOSアプリ開発におけるデバイス選択 / Appropriate choise of supporting devices on iOS app development
mogaming
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
RailsのPull requestsのレビューの時に私が考えていること
yahonda
5
1.7k
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
840
開発効率向上のためのリファクタリングの一歩目の選択肢 ~コード分割~ / JJUG CCC 2024 Fall
ryounasso
0
360
CSC509 Lecture 09
javiergs
PRO
0
110
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
440
Identifying User Idenity
moro
6
7.9k
offers_20241022_imakiire.pdf
imakurusu
2
360
Kaigi on Rails 2024 - Rails APIモードのためのシンプルで効果的なCSRF対策 / kaigionrails-2024-csrf
corocn
5
3.4k
デプロイを任されたので、教わった通りにデプロイしたら障害になった件 ~俺のやらかしを越えてゆけ~
techouse
52
32k
Universal Linksの実装方法と陥りがちな罠
kaitokudou
1
220
カラム追加で増えるActiveRecordのメモリサイズ イメージできますか?
asayamakk
4
1.5k
Vaporモードを大規模サービスに最速導入して学びを共有する
kazukishimamoto
4
4.3k
Featured
See All Featured
KATA
mclloyd
29
13k
Why You Should Never Use an ORM
jnunemaker
PRO
53
9k
Imperfection Machines: The Place of Print at Facebook
scottboms
264
13k
Into the Great Unknown - MozCon
thekraken
31
1.5k
GraphQLとの向き合い方2022年版
quramy
43
13k
Side Projects
sachag
452
42k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
9
680
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
Building Your Own Lightsaber
phodgson
102
6k
Product Roadmaps are Hard
iamctodd
PRO
48
10k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
355
29k
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 ࠓޙͷΞοϓσʔτʹظͰ͖ΔͷͰΨγΨγ ͍͖͍ͬͯͨ♻