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.6k
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
470
Firebaseでつくるグループチェックリスト管理サービス / check list apps on firebase
mogaming
5
570
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.2k
Other Decks in Programming
See All in Programming
OpenTelemetryを活用したObservability入門 / Introduction to Observability with OpenTelemetry
seike460
PRO
1
340
英語 × の私が、生成AIの力を借りて、OSSに初コントリビュートした話
personabb
0
100
Windows版PHPのビルド手順とPHP 8.4における変更点
matsuo_atsushi
0
370
MCP世界への招待: AIエンジニアが創る次世代エージェント連携の世界
gunta
2
590
複数ドメインに散らばってしまった画像…! 運用中のPHPアプリに後からCDNを導入する…!
suguruooki
0
430
体得しよう!RSA暗号の原理と解読
laysakura
3
540
今から始めるCursor / Windsurf / Cline
kengo_hayano
0
110
エンジニア未経験が最短で戦力になるためのTips
gokana
0
220
remix + cloudflare workers (DO) docker上でいい感じに開発する
yoshidatomoaki
0
120
小さく段階的リリースすることで深夜メンテを回避する
mkmk884
2
130
OUPC2024 Day 1 解説
kowerkoint
0
400
爆速スッキリ! Rspack 移行の成果と道のり - Muddy Web #11
dora1998
1
150
Featured
See All Featured
Large-scale JavaScript Application Architecture
addyosmani
511
110k
Visualization
eitanlees
146
16k
Fontdeck: Realign not Redesign
paulrobertlloyd
83
5.5k
Why You Should Never Use an ORM
jnunemaker
PRO
55
9.3k
Reflections from 52 weeks, 52 projects
jeffersonlam
349
20k
The World Runs on Bad Software
bkeepers
PRO
67
11k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7.1k
The Power of CSS Pseudo Elements
geoffreycrofte
75
5.7k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
60k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.5k
Why Our Code Smells
bkeepers
PRO
336
57k
Agile that works and the tools we love
rasmusluckow
328
21k
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 ࠓޙͷΞοϓσʔτʹظͰ͖ΔͷͰΨγΨγ ͍͖͍ͬͯͨ♻