Firebase Remote Configでアプリのアップデート促進を実装する

Firebase Remote Configでアプリのアップデート促進を実装する

E77b6a5f919f7366d94f21eee9a014f5?s=128

operandoOS

June 23, 2017
Tweet

Transcript

  1. Firebase Remote ConfigͰ
 ΞϓϦͷΞοϓσʔτଅਐ Λ࣮૷͢Δ Otemachi Firebase #2

  2. About Me Shinobu Okano @operandoOS Mercari, Inc. Souzoh, Inc.

  3. None
  4. ͓࿩͢ΔΞοϓσʔτଅਐͱ͸

  5. Ξοϓσʔτଅਐ࣮૷ͯ͠Δਓʁ✋

  6. Firebase Remote Config? Change the behavior and appearance of your

    app without publishing an app update. https://firebase.google.com/docs/remote-config/
  7. Firebase Remote Config?

  8. ͳͥFirebase Remote Configͳͷ͔ʁ • ୭Ͱ΋ΞοϓσʔτଅਐΛ഑৴͢Δ࡞ۀ͕Ͱ͖Δ • औΓԼ͛Δͷ΋ಉ༷ʹ • APIͷ࣮૷͕ͳͯ͘΋͍͍ •

    iOS͚ͩʹ௨஌Λग़͢ͱ͔OSผʹग़͠෼͚͕Ͱ͖Δ
  9. ΞϓϦͷΞοϓσʔτଅਐʹ
 ඞཁͳ΋ͷ(Ұྫ)

  10. μΠΞϩάͰΞοϓσʔτ಺༰ Λදࣔ͢Δ͜ͱΛ૝ఆ

  11. μΠΞϩάͰΞοϓσʔτ಺༰ Λදࣔ͢Δ͜ͱΛ૝ఆ • Ξοϓσʔτର৅ͷΞϓϦͷόʔδϣϯ • ΞοϓσʔτଅਐΛग़͔͢ɺग़͞ͳ͍͔ • ΞοϓσʔτจݴͷλΠτϧ • Ξοϓσʔτจݴͷຊจ

  12. ͲͷΑ͏ʹΞοϓσʔτଅਐͷ஋Λ
 Remote Configʹઃఆ͢Δ͔

  13. JSON

  14. ͲͷΑ͏ʹΞοϓσʔτଅਐͷ஋ ΛRemote Configʹઃఆ͢Δ͔ • Ξοϓσʔτଅਐͷ஋ΛJSONจࣈྻʹͯ͠ઃఆ • JSON͸minify͢Δ • ͦͷJSONΛΫϥΠΞϯτଆͰΑ͠ͳʹॲཧ͢Δ

  15. JSONͷྫ { "update_application_version": 2, "is_show_update_notice": true, "update_title": "Ξοϓσʔτͷ͓஌Βͤ", "update_message": "Ξοϓσʔτ಺༰Λΰχϣΰχϣ…"

    }
  16. Remote Configͷ஋ʹ͸
 ͲΕ͘Β͍ͷจࣈྻ͕ೖΔͷʁ The total length of parameter value strings

    within a project cannot exceed 500,000 characters. https://firebase.google.com/docs/remote-config/ parameters#limits_on_parameters_and_conditions
  17. ࣮૷͸ΘΓͱ؆୯ • Remote ConfigΛॳظԽ • Remote Config Serverͷ஋ΛfetchͰऔಘͯ͠ߋ৽ • Ξοϓσʔτଅਐͷ஋Λࢦఆͨ͠Key໊Ͱ಺༰Λऔಘ

    • Remote Config͔Βऔಘͨ͠஋ͷνΣοΫ • ஋ΛνΣοΫͯ͠ɺΞοϓσʔτଅਐΛग़͢ඞཁ͕͋Δͱ ൑அͨ͠Βग़͢
  18. public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle

    savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); RemoteConfig.init(this); RemoteConfig.updateConfig(this, task -> { RemoteConfig.getUpdateNoticeConfig(this) .filter(value -> !TextUtils.isEmpty(value)) .flatMap(UpdateNotice::parseJson) .filter(value -> getSharedPreferences("update_notice", Context.MODE_PRIVATE).getInt("showed_update_notice_version", 0) < value.updateApplicationVersion) .filter(value -> BuildConfig.VERSION_CODE < value.updateApplicationVersion) .ifPresent(this::showUpdateDialog); }); } private void showUpdateDialog(UpdateNotice updateNotice) { new AlertDialog.Builder(this) .setTitle(updateNotice.updateTitle) .setMessage(updateNotice.updateMessage) .setPositiveButton("Ξοϓσʔτ͢Δ", (dialogInterface, i) -> { IntentUtil.openGooglePlayAppDetails(this, getPackageName()); }) .setNegativeButton("ด͡Δ", (dialogInterface, i) -> { }) .show(); getSharedPreferences("update_notice", Context.MODE_PRIVATE) .edit() .putInt("showed_update_notice_version", updateNotice.updateApplicationVersion) .apply(); } }
  19. Remote ConfigͷWrapper https://github.com/operando/ FirebaseRemoteConfigUpdateNotice/blob/ master/app/src/main/java/com/os/operando/ updatenotice/sample/RemoteConfig.java Remote ConfigͷLibraryͷ࢖͍ํ͸ҎԼࢀর

  20. RemoteConfig.init(this); Remote ConfigΛॳظԽ

  21. Remote Config Serverͷ஋Λ
 fetchͰऔಘͯ͠ߋ৽ RemoteConfig.updateConfig(this, task -> { // ͜͜ʹΰχϣΰχϣॻ͖·͢

    });
  22. Ξοϓσʔτଅਐͷ஋Λࢦఆ͠ ͨKey໊Ͱ಺༰Λऔಘ RemoteConfig.updateConfig(this, task -> { RemoteConfig.getUpdateNoticeConfig(this); });

  23. Remote Config͔Βऔಘͨ͠
 ஋ͷνΣοΫ RemoteConfig.updateConfig(this, task -> { RemoteConfig.getUpdateNoticeConfig(this) .filter(value ->

    !TextUtils.isEmpty(value)) .flatMap(UpdateNotice::parseJson) .filter(v -> BuildConfig.VERSION_CODE < v.updateApplicationVersion); });
  24. ஋ΛνΣοΫͯ͠ɺΞοϓσʔτଅਐ Λग़͢ඞཁ͕͋Δͱ൑அͨ͠Βग़͢ RemoteConfig.updateConfig(this, task -> { RemoteConfig.getUpdateNoticeConfig(this) .filter(value -> !TextUtils.isEmpty(value))

    .flatMap(UpdateNotice::parseJson) .filter(v -> BuildConfig.VERSION_CODE < v.updateApplicationVersion) .ifPresent(this::showUpdateDialog); });
  25. ΞοϓσʔτଅਐͷμΠΞϩάදࣔ private void showUpdateDialog(UpdateNotice updateNotice) { new AlertDialog.Builder(this) .setTitle(updateNotice.updateTitle) .setMessage(updateNotice.updateMessage)

    .setPositiveButton("Ξοϓσʔτ͢Δ", (dialogInterface, i) -> { IntentUtil.openGooglePlayAppDetails(this, getPackageName()); }) .setNegativeButton("ด͡Δ", (dialogInterface, i) -> { }) .show(); }
  26. Sample https://github.com/operando/ FirebaseRemoteConfigUpdateNotice

  27. ӡ༻໘Ͱͷ՝୊ • Remote Configʹઃఆ͢Δ஋ͷJSONจࣈྻΛͲͷΑ͏ʹ࡞੒͢Δ͔ • ࡞੒༻ͷࡶͳπʔϧ࡞Δͱ͔ • Ξοϓσʔτͨ͠ΞϓϦʹ໰୊͕͋ͬͨ৔߹ɺ௨஌ͯ͠͠·ͬͨ
 ಺༰ΛऔΓԼ͛ͯ൓ө͞ΕΔ·Ͱͷ͕࣌ؒ͋Δ •

    Ξοϓσʔτͨ͠ΞϓϦʹ໰୊ͳ͍Ͷʂ͕Θ͔͔ͬͯΒ
 ੾Γସ͑Δ
  28. ࢀߟ FirebaseͷRemoteConfigΛ༻͍ͯAndorid
 ΞϓϦͷΞοϓσʔτૌٻ௨஌Λग़͢ํ๏Λ
 ߟ͑ͯΈͨ http://qiita.com/masaibar/items/f32a788159f210abd262

  29. Thanks!!