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

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

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

operandoOS

June 23, 2017
Tweet

More Decks by operandoOS

Other Decks in Technology

Transcript

  1. Firebase Remote ConfigͰ

    ΞϓϦͷΞοϓσʔτଅਐ
    Λ࣮૷͢Δ
    Otemachi Firebase #2

    View Slide

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

    View Slide

  3. View Slide

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

    View Slide

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

    View Slide

  6. Firebase Remote Config?
    Change the behavior and
    appearance of your app without
    publishing an app update.
    https://firebase.google.com/docs/remote-config/

    View Slide

  7. Firebase Remote Config?

    View Slide

  8. ͳͥFirebase Remote Configͳͷ͔ʁ
    • ୭Ͱ΋ΞοϓσʔτଅਐΛ഑৴͢Δ࡞ۀ͕Ͱ͖Δ
    • औΓԼ͛Δͷ΋ಉ༷ʹ
    • APIͷ࣮૷͕ͳͯ͘΋͍͍
    • iOS͚ͩʹ௨஌Λग़͢ͱ͔OSผʹग़͠෼͚͕Ͱ͖Δ

    View Slide

  9. ΞϓϦͷΞοϓσʔτଅਐʹ

    ඞཁͳ΋ͷ(Ұྫ)

    View Slide

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

    View Slide

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

    View Slide

  12. ͲͷΑ͏ʹΞοϓσʔτଅਐͷ஋Λ

    Remote Configʹઃఆ͢Δ͔

    View Slide

  13. JSON

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

  17. ࣮૷͸ΘΓͱ؆୯
    • Remote ConfigΛॳظԽ
    • Remote Config Serverͷ஋ΛfetchͰऔಘͯ͠ߋ৽
    • Ξοϓσʔτଅਐͷ஋Λࢦఆͨ͠Key໊Ͱ಺༰Λऔಘ
    • Remote Config͔Βऔಘͨ͠஋ͷνΣοΫ
    • ஋ΛνΣοΫͯ͠ɺΞοϓσʔτଅਐΛग़͢ඞཁ͕͋Δͱ
    ൑அͨ͠Βग़͢

    View Slide

  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();
    }
    }

    View Slide

  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ͷ࢖͍ํ͸ҎԼࢀর

    View Slide

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

    View Slide

  21. Remote Config Serverͷ஋Λ

    fetchͰऔಘͯ͠ߋ৽
    RemoteConfig.updateConfig(this, task -> {
    // ͜͜ʹΰχϣΰχϣॻ͖·͢
    });

    View Slide

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

    View Slide

  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);
    });

    View Slide

  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);
    });

    View Slide

  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();
    }

    View Slide

  26. Sample
    https://github.com/operando/
    FirebaseRemoteConfigUpdateNotice

    View Slide

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

    ಺༰ΛऔΓԼ͛ͯ൓ө͞ΕΔ·Ͱͷ͕࣌ؒ͋Δ
    • Ξοϓσʔτͨ͠ΞϓϦʹ໰୊ͳ͍Ͷʂ͕Θ͔͔ͬͯΒ

    ੾Γସ͑Δ

    View Slide

  28. ࢀߟ
    FirebaseͷRemoteConfigΛ༻͍ͯAndorid

    ΞϓϦͷΞοϓσʔτૌٻ௨஌Λग़͢ํ๏Λ

    ߟ͑ͯΈͨ
    http://qiita.com/masaibar/items/f32a788159f210abd262

    View Slide

  29. Thanks!!

    View Slide