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. 'JSFCBTFΛ࢖ͬͯΈͨ ,BUTVZB,BUP

  2. ࣗݾ঺հ w Ճ౻উ໵ w ૊ΈࠐΈۀք͔ΒϞόΠϧۀքʹ
 ΍͖ͬͯͯ೥ w ڈ೥຤ʹຊग़͠·ͨ͠

  3. 'JSFCBTFΛ ࢖ͬͯΈͨ࿩Λ͠·͢

  4. 'JSFCBTFͱ͸ w ೥݄ʹ(PPHMFʹങऩ͞Εͨ#BB4ʢ#BDLFOEBTB 4FSWJDFʣ w ετϨʔδɺϢʔβʔ؅ཧͳͲΞϓϦέʔγϣϯͷόοΫΤϯ υͱͯ͠ඞཁͱͳΔػೳΛαʔϏεΛఏڙͯ͘͠ΕΔ w νϟοτΞϓϦͷΑ͏ͳϦΞϧλΠϜʹσʔλΛಉظ͢Δඞཁ ͕͋ΔαʔϏεʹద͍ͯ͠Δ

    w /P42-ɻ+40/ΦϒδΣΫτͱͯ͠อ࣋͞ΕΔ w ΦϑϥΠϯͷॲཧ΋͍͍ײ͡ʹ΍ͬͯ͘ΕΔʢΒ͍͠ʣ
  5. ͳͥ'JSFCBTF͔

  6. ͳͥ'JSFCBTFͳͷ͔ w J04"OESPJEͰखܰʹ࢖͏͜ͱ͕Ͱ͖Δ΋ͷΛ ୳ͯͨ͠ w ಥવͷ1BSTFDPNऴྃͷ͓஌Βͤ w ͪΐͬͱ࢖͏͚ͩͳΒֶशίετ͕௿ͯ͘ࡁΉ ͷ΋ͷΛɾɾɾ

  7. ࢖ͬͯΈΔ

  8. ΞΧ΢ϯτొ࿥ w IUUQTXXXpSFCBTFDPN

  9. ؅ཧը໘

  10. ؅ཧը໘ ௥Ճ͞Εͨσʔλ͕ ͜͜ʹදࣔ͞Ε͍ͯ͘

  11. νϟοτΞϓϦΛ ࡞ͬͯΈΔ

  12. None
  13. 4%,ͷಋೖ

  14. $PDPB1PET

  15. pod 'Firebase'

  16. ॳظઃఆˍಡΈॻ͖

  17. ॳظઃఆ firebaseRef = Firebase(url:"https:// kanmoba.firebaseio.com/chat/message")

  18. σʔλͷॻ͖ࠐΈ let messageData = ["name":nameTextField.text!, "message": messageTextField.text!] firebaseRef.childByAutoId().setValue(messageData) /4%JDUJPOBSZͰॻ͖ࠐΉσʔλΛ४උ *%ΛϥϯμϜͰੜ੒͢Δϝιου

    σʔλͷॻ͖ࠐΈʢૹ৴ʣ
  19. ؅ཧը໘ͰݟͯΈΔ

  20. σʔλͷಡΈग़͠ 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Λࢦఆͯ͠஋ΛಘΔ
  21. σϞ

  22. None
  23. ෼͘Β͍Ͱ Ͱ͖ͯ͠·ͬͨͷͰ

  24. "OESPJE΋ɾɾɾ

  25. 4%,

  26. (SBEMF

  27. 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+'
 }
  28. HSBEMFCVMJE packagingOptions {
 exclude 'META-INF/LICENSE'
 exclude 'META-INF/LICENSE-FIREBASE.txt'
 exclude 'META-INF/NOTICE'
 }

  29. ॳظઃఆˍಡΈॻ͖

  30. ͦͷલʹ1FSNJTTJPO <uses-permission android:name="android.permission.INTERNET" />

  31. ॳظઃఆ Firebase.setAndroidContext(this);
 firebaseRef = new Firebase("https://kanmoba.firebaseio.com/ chat/message");

  32. σʔλͷॻ͖ࠐΈ 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ϝιου͕ ແ͔ͬͨɾɾɾ
  33. σʔλͷಡΈग़͠ 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"));
 } } ϦεφʔΛొ࿥
  34. σϞ

  35. None
  36. ͦͷଞؾʹͳΔͱ͜ΖΛ

  37. όΠφϦ͸ʁ w #"4&Τϯίʔυ͢Ε͹0,

  38. Ձ֨

  39. ηΩϡϦςΟ w ʮ3VMFTʯΛઃఆ͢Δ͜ͱͰΞΫηε੍ݶ͕Ͱ͖Δ

  40. σʔλͷαΠζΛ੍ݶ

  41. ϩάΠϯ͍ͯ͠ΔਓͷΈڐՄ

  42. ؾʹͳΔ͜ͱ w σʔλ͕૿͑ͨ࣌ʹ଎౓͕஗͘ͳΒͳ͍͔ʁ w 'JSFCBTFʹ͸164)഑৴ػೳ͕ແ͍ w 1FSTFΛϗεςΟϯάͨ͠ํ͕΍ͬͺΓྑ͍ʁ w Φεεϝͷ#BB4͕஌Γ͍ͨ

  43. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠