firebase勉強会資料

6cdb33045501f0d30733e9cdfb739f7e?s=47 gupuru
October 03, 2016

 firebase勉強会資料

6cdb33045501f0d30733e9cdfb739f7e?s=128

gupuru

October 03, 2016
Tweet

Transcript

  1. None
  2. About me ৽ݟ ߊฏ גࣜձࣾηϑϦͱ͍͏ձࣾͰɺYAMAPͷAndroidΞϓϦΛ࡞͍ͬͯΔ iOSΤϯδχΞͰ͢ɻ ࠷ۙ͸ɺTensorFlow, Docker, Angular2ͳͲ΍͍ͬͯͯiOSશવ Ͱ͖ͯͳ͍ʢٽʣ

    » Twitter: @gupuru » GitHub: gupuru
  3. ηϑϦ͸ɺͲΜͳاۀ͔ͱݴ͏ͱ…ࣾ௕͕ݘͰ͢ʂ

  4. FirebaseͬͯɺԿʁ

  5. Firebase » mBaaS » ΞϓϦ΍Web։ൃʹඞཁͳػೳ͕਺ଟ͘ఏڙ͞Ε͍ͯΔ » Google͕ӡӦ͍ͯ͠ΔαʔϏε » 2011೥ελʔτ(2014೥ޙ൒ʹGoogle͕ങऩ) »

    ແྉͰ͔ͭ͑Δ΋ͷ͕ଟ͍
  6. None
  7. None
  8. ͕࣌ؒڐ͢ݶΓɺ঺հ͍ͯ͘͠Αʔ

  9. Analytics

  10. Analytics » ϞόΠϧΞϓϦʹಛԽͨ͠ Google ΞφϦςΟΫεΈ͍ͨͳ΋ͷ » Πϕϯτܕ෼ੳπʔϧ » ແྉ »

    iOS, Android
  11. iOSͷಋೖ pod 'Firebase/Core' import UIKit import Firebase @UIApplicationMain class AppDelegate:

    UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { //௥Ճ FIRApp.configure() return true } }
  12. Androidͷಋೖ compile 'com.google.firebase:firebase-core:9.6.1' public class MainActivity extends AppCompatActivity { private

    final MainActivity self = this; private FirebaseAnalytics mFirebaseAnalytics; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); } }
  13. None
  14. Cloud Messaging

  15. Cloud Messaging » ϓογϡ௨஌ » iOS, Android, Web » ແྉ

    » Notification MessageͱData Messageͷ̎छྨ
  16. Notification Message { "to" : "HHwgIpoDKCIZvvDMExUdFQ3P1...", "notification" : { "body"

    : "΅Ͱ͍", "title" : "͍ͨͱΔ", "icon" : "myicon" } } curl --header "Authorization: key=...guQidTc7xzs8" \ --header Content-Type:"application/json" \ https://fcm.googleapis.com/fcm/send \ -d "{\"to\": \"...ifS-oaJevN_VwU0Y\",\"priority\":\"high\",\"notification\": {\"title\": \"this is title\", \"body\": \"this is body\"}}"
  17. Data Message { "to" : "xUdFQ3P1...", "data" : { "name"

    : "fox", "body" : "neko", "Place" : "horaana" }, } curl --header "Authorization: key=...guQidTc7xzs8" \ --header Content-Type:"application/json" \ https://fcm.googleapis.com/fcm/send \ -d "{\"to\": \"...aJevN_VwU0Y\",\"priority\":\"high\",\"data\": {\"custom_title\": \"this is custom title\", \"custom_body\": \"this is custom body\", \"icon\": \"ic_stat_ic_notification\"}}"
  18. Androidͷಋೖ compile 'com.google.firebase:firebase-messaging:9.6.1'

  19. tokenऔಘ FirebaseInstanceId.getInstance().getToken();

  20. ௨஌ͷϋϯυϦϯά public class MyFirebaseMessagingService extends FirebaseMessagingService { public void onMessageReceived(RemoteMessage

    remoteMessage) { Log.d(TAG, "From: " + remoteMessage.getFrom()); if (remoteMessage.getData() != null) { //data } if (remoteMessage.getNotification() != null) { //notification } } } <service android:name=".MyFirebaseMessagingService"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT"/> </intent-filter> </service>
  21. Notifications

  22. Notifications » ϓογϡ௨஌ » Webίϯιʔϧ͔Β࢖͏(ίʔυΛॻ͘ඞཁͳ͠) » ແྉ » iOS, Android

  23. None
  24. Authentication

  25. Authentication » ϩάΠϯपΓ » ϝΞυ, ಗ໊ΞΧ΢ϯτ, Google, Facebook, Twitter, GitHubͳͲʹରԠ

    » ແྉ » FirebaseUIΛ࢖͑͹ɺuiͳͲ΋؆୯ʹ࣮૷Ͱ͖Δ » iOS, Android, Web
  26. None
  27. Androidͷಋೖ(firebase UI) compile 'com.firebaseui:firebase-ui-auth:0.6.0' FirebaseAuth auth = FirebaseAuth.getInstance(); if (auth.getCurrentUser()

    != null) { //ϩάΠϯࡁΈ } else { startActivityForResult( AuthUI.getInstance().createSignInIntentBuilder().build(), RC_SIGN_IN); } protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RC_SIGN_IN) { if (resultCode == RESULT_OK) { // ϩάΠϯ੒ޭ } } }
  28. Webͷ৔߹ <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Firebase ui sample</title>

    <!-- firebaseͷ͋ΕΛషͬͯ͜͜ʹ --> <script src="https://www.gstatic.com/firebasejs/ui/live/0.5/firebase-ui-auth.js"></script> <link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/live/0.5/firebase-ui-auth.css" /> <script type="text/javascript"> // FirebaseUI config. var uiConfig = { 'signInSuccessUrl': '੒ޭޙͷurl', 'signInOptions': [ firebase.auth.FacebookAuthProvider.PROVIDER_ID, firebase.auth.EmailAuthProvider.PROVIDER_ID ], }; var ui = new firebaseui.auth.AuthUI(firebase.auth()); ui.start('#firebaseui-auth-container', uiConfig); </script> </head> <body> <div id="firebaseui-auth-container"></div> </body> </html>
  29. None
  30. Realtime Database

  31. Realtime Database » NoSQL JSON σʔλϕʔε » ϦΞϧλΠϜಉظ(ΦϑϥΠϯରԠ) » iOS,

    Android, Web » ༗ྉ(ແྉ࿮͋Γ)
  32. iOSͷಋೖ pod 'Firebase/Database' import UIKit import Firebase @UIApplicationMain class AppDelegate:

    UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { //௥Ճ FIRApp.configure() return true } }
  33. import UIKit import FirebaseDatabase class ViewController: UIViewController { let rootRef

    = FIRDatabase.database().reference() override func viewDidLoad() { super.viewDidLoad() //ಡΈࠐΈ rootRef.observe(.value, with: { snapshot in print("\(snapshot.key) -> \(snapshot.value)") }) //ॻ͖ࠐΈ rootRef.child("food").setValue("ΓΜ͝͞·") } }
  34. None
  35. Storage

  36. Storage » ετϨʔδ(S3ʹ͍͔ۙ΋) » ը૾, ಈը, Ի੠ͳͲͷμ΢ϯϩʔυ, Ξοϓϩʔυ » iOS,

    Android, Web » ༗ྉ(ແྉ࿮͋Γ)
  37. iOSͷಋೖ pod 'Firebase/Storage' import UIKit import Firebase @UIApplicationMain class AppDelegate:

    UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { //௥Ճ FIRApp.configure() return true } }
  38. Ξοϓϩʔυ import FirebaseStorage class ViewController: UIViewController { let storage =

    FIRStorage.storage() override func viewDidLoad() { super.viewDidLoad() let storageRef = storage.reference(forURL: "gs://fir-handson-ce2a8.appspot.com") if let data = UIImagePNGRepresentation(UIImage(named: "ie")!) { let riversRef = storageRef.child("images/ie.png") riversRef.put(data, metadata: nil, completion: { metaData, error in print(metaData) print(error) }) } } }
  39. None
  40. μ΢ϯϩʔυ import FirebaseStorage class ViewController: UIViewController { let storage =

    FIRStorage.storage() override func viewDidLoad() { super.viewDidLoad() let storageRef = storage.reference(forURL: "gs://fir-handson-ce2a8.appspot.com") let ieRef = storageRef.child("images/hogehoge.png") ieRef.data(withMaxSize: 1 * 1024 * 1024) { (data, error) -> Void in if (error != nil) { print(error) } else { let image: UIImage! = UIImage(data: data!) } } } }
  41. None
  42. Hosting

  43. Hosting » WebαΠτެ։ » HTTP/2, SSL » ༗ྉ(ແྉ࿮͋Γ) » ಠࣗυϝΠϯՄೳ(ແྉ)

  44. ಋೖ npm install -g firebase-tools ॳظԽ firebase init

  45. None
  46. ެ։ firebase deploy ֬ೝ firebase open

  47. Crash Reporting

  48. Crash Reporting » ΫϥογϡϨϙʔτ » ϕʔλ » ແྉ » iOS,

    Android
  49. Androidͷಋೖ compile 'com.google.firebase:firebase-crash:9.6.1'

  50. None
  51. Remote Config

  52. Remote Config » Ϋϥ΢υͰϞόΠϧΞϓϦͷઃఆ஋Λ؅ཧͰ͖ΔαʔϏε » iOS, Android » ແྉ

  53. Androidͷಋೖ compile 'com.google.firebase:firebase-config:9.6.1'

  54. σϑΥϧτ஋ͷઃఆ <?xml version="1.0" encoding="utf-8"?> <defaultsMap> <entry> <key>test</key> <value>ͯ͢</value> </entry> </defaultsMap>

  55. FirebaseRemoteConfig remoteConfig; remoteConfig = FirebaseRemoteConfig.getInstansce(); //σϕϩούʔϞʔυࢦఆ FirebaseRemoteConfigSettings configSettings = new

    FirebaseRemoteConfigSettings.Builder() .setDeveloperModeEnabled(BuildConfig.DEBUG) .build(); remoteConfig.setConfigSettings(configSettings); //σϑΥϧτͷ஋ΛಡΈࠐΉ remoteConfig.setDefaults(R.xml.remote_config_defaults); remoteConfig.fetch(43200) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { //஋Λ൓ө remoteConfig.activateFetched(); } else { //fetchࣦഊ } } });
  56. None
  57. App Indexing

  58. App Indexing » ΢ΣϒαΠτͱΞϓϦΛඥ෇͚Δ » ແྉ » iOS, Android

  59. ɹσΟʔϓϦϯΫͷઃఆ(Andoirdͷ৔߹) <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />

    <action android:name="android.intent.action.VIEW" /> <data android:scheme="https" android:host="fir-sample-51a1e.firebaseapp.com" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> </intent-filter> </activity>
  60. ςετ adb shell am start -a android.intent.action.VIEW -d "url" com.example.hoe

  61. Dynamic Links

  62. Dynamic Links » ΞϓϦͷΠϯετʔϧଅਐ » ແྉ » iOS, Android

  63. Androidͷಋೖ compile 'com.google.firebase:firebase-invites:9.6.1'

  64. None
  65. Invites

  66. Invites » γΣΞػೳ » ແྉ » iOS, Android

  67. Androidͷಋೖ compile 'com.google.firebase:firebase-invites:9.6.1' ※Dynamic Linksͷ༗ޮ͕ඞཁ

  68. ট଴ Intent intent = new AppInviteInvitation.IntentBuilder(getString(R.string.invitation_title)) .setMessage(getString(R.string.invitation_message)) .setDeepLink(Uri.parse(getString(R.string.invitation_deep_link))) .setCustomImage(Uri.parse(getString(R.string.invitation_custom_image))) .setCallToActionText(getString(R.string.invitation_cta))

    .build(); startActivityForResult(intent, REQUEST_INVITE); ݁Ռ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_INVITE) { if (resultCode == RESULT_OK) { String[] ids = AppInviteInvitation.getInvitationIds(resultCode, data); for (String id : ids) { Log.d(TAG, "onActivityResult: sent invitation " + id); } } } }
  69. ड৴ @Override protected void onCreate(Bundle savedInstanceState) { mGoogleApiClient = new

    GoogleApiClient.Builder(this) .addApi(AppInvite.API) .enableAutoManage(this, this) .build(); boolean autoLaunchDeepLink = true; AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, this, autoLaunchDeepLink) .setResultCallback( new ResultCallback<AppInviteInvitationResult>() { @Override public void onResult(AppInviteInvitationResult result) { if (result.getStatus().isSuccess()) { Intent intent = result.getInvitationIntent(); String deepLink = AppInviteReferral.getDeepLink(intent); String invitationId = AppInviteReferral.getInvitationId(intent); } } }); }
  70. ·ͱΊ

  71. Firebaseศརͩͧ(ŋТŋ)b

  72. ࠷ޙʹݴ͍๨Εͨ͜ͱ͕...

  73. ࣾ௕ͷ໊લ͸ɺϋφͪΌΜͰ͢ʢসʣ

  74. ͝ਗ਼ௌɺ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ