質問編集履歴
1
内容を詳細に
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,11 +1,75 @@
|
|
1
|
-
### 前提
|
1
|
+
### 前提
|
2
2
|
|
3
|
+
1. `expo init`でアプリを作成
|
4
|
+
1. `yarn add firebase`でfirebaseをインストール
|
5
|
+
1. firebaseコンソールからwebアプリの作成
|
6
|
+
1. App.jsに以下のようなコードを記述
|
7
|
+
```
|
3
|
-
|
8
|
+
import React from 'react';
|
9
|
+
import { StyleSheet, Text, View } from 'react-native';
|
4
10
|
|
11
|
+
//firebase
|
12
|
+
//firebaseコンソールのやつをコピペ
|
13
|
+
import * as firebase from 'firebase';
|
14
|
+
import 'firebase/firestore';
|
15
|
+
const firebaseConfig = {
|
16
|
+
apiKey: "*********************",
|
17
|
+
authDomain: "*********************",
|
18
|
+
databaseURL: "*********************",
|
19
|
+
projectId: "*********************",
|
20
|
+
storageBucket: "*********************",
|
21
|
+
messagingSenderId: "*********************",
|
22
|
+
appId: "*********************",
|
23
|
+
measurementId: "*********************"
|
24
|
+
};
|
25
|
+
if(!firebase.apps.length){
|
26
|
+
firebase.initializeApp(firebaseConfig);
|
27
|
+
}
|
5
28
|
|
29
|
+
export const db = firebase.firestore();
|
30
|
+
|
31
|
+
export default class App extends React.Component {
|
32
|
+
|
33
|
+
componentDidMount(){
|
34
|
+
|
35
|
+
const citiesRef = db.collection('cities');
|
36
|
+
// データをFireStoreに保存
|
37
|
+
let setSf = citiesRef.doc('SF').set({
|
38
|
+
name: 'San Francisco', state: 'CA', country: 'USA',
|
39
|
+
capital: false, population: 860000,
|
40
|
+
date: new Date()
|
41
|
+
});
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
render(){
|
46
|
+
return (
|
47
|
+
<View style={styles.container}>
|
48
|
+
<Text>Open up App.js to start working on your app!</Text>
|
49
|
+
</View>
|
50
|
+
);
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
const styles = StyleSheet.create({
|
55
|
+
container: {
|
56
|
+
flex: 1,
|
57
|
+
backgroundColor: '#fff',
|
58
|
+
alignItems: 'center',
|
59
|
+
justifyContent: 'center',
|
60
|
+
},
|
61
|
+
});
|
62
|
+
|
63
|
+
```
|
64
|
+
|
65
|
+
|
6
66
|
### 発生している問題・エラーメッセージ
|
7
67
|
|
68
|
+
上記の状態で、
|
8
|
-
|
69
|
+
Expoのメニューで「Debug Remote JS」を押して、起動すると、
|
70
|
+
しっかりFireStoreにデータが保存されるのですが、
|
9
|
-
|
71
|
+
Expoのメニューで「Stop Remote Debugging」を押して、起動すると
|
72
|
+
何も保存されません。
|
10
73
|
|
11
|
-
|
74
|
+
Stop Remote Debuggingの状態でもデータを保存することができるようにしたいです。
|
75
|
+
よろしくお願いいたします。
|