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
最新TCAキャッチアップ
0si43
0
140
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
220
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
100
受け取る人から提供する人になるということ
little_rubyist
0
230
Realtime API 入門
riofujimon
0
150
ヤプリ新卒SREの オンボーディング
masaki12
0
130
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
Featured
See All Featured
BBQ
matthewcrist
85
9.3k
Designing Experiences People Love
moore
138
23k
Code Review Best Practice
trishagee
64
17k
Ruby is Unlike a Banana
tanoku
97
11k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Code Reviewing Like a Champion
maltzj
520
39k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
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 ࠓޙͷΞοϓσʔτʹظͰ͖ΔͷͰΨγΨγ ͍͖͍ͬͯͨ♻