Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Firebaseを使ってみた

 Firebaseを使ってみた

関西モバイルアプリ研究会 #11 資料

Katsuya Kato

February 24, 2016
Tweet

More Decks by Katsuya Kato

Other Decks in Technology

Transcript

  1. σʔλͷಡΈग़͠ firebaseRef.observeEventType(.ChildAdded, withBlock: { snapshot in if let name =

    snapshot.value.objectForKey("name") as? String, message = snapshot.value.objectForKey("message") as? String { self.textView.text = "\(self.textView.text)\n\(name) : \(message)" } }) ؂ࢹ͢ΔΠϕϯτΛొ࿥ ࢠ͕௥Ճ͞Εͨͱ͖Λ؂ࢹ͢Δ LFZΛࢦఆͯ͠஋ΛಘΔ
  2. 4%,

  3. HSBEMFCVMJE dependencies {
 compile fileTree(dir: 'libs', include: ['*.jar'])
 testCompile 'junit:junit:4.12'


    compile 'com.android.support:appcompat-v7:23.1.1'
 compile 'com.firebase:firebase-client-android:2.5.2+'
 }
  4. σʔλͷॻ͖ࠐΈ HashMap<String, String> post = ɹɹɹɹɹɹɹɹɹɹɹɹɹɹɹnew HashMap<String, String>();
 post.put("name", nameEditText.getText().toString());


    post.put("message", messageEditText.getText().toString());
 
 firebaseRef.push().setValue(post) DIJME#Z"VUP*Eϝιου͕ ແ͔ͬͨɾɾɾ
  5. σʔλͷಡΈग़͠ firebaseRef.addChildEventListener(new ChildEventListener() {
 @Override
 public void onChildAdded(DataSnapshot dataSnapshot, String

    s) {
 HashMap hash = (HashMap)dataSnapshot.getValue();
 textView.setText(textView.getText() + ɹɹɹɹɹɹɹɹɹɹ ɹɹɹɹ"\n" + hash.get("name") + " : " + ɹɹɹɹɹɹɹɹɹɹɹɹɹɹ hash.get("message"));
 } } ϦεφʔΛొ࿥