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

Propagate Remote Config updates in real time

2594ac7ce91fd7d9a3ce71ca7cc2d0c0?s=47 d_date
November 14, 2018

Propagate Remote Config updates in real time

2594ac7ce91fd7d9a3ce71ca7cc2d0c0?s=128

d_date

November 14, 2018
Tweet

Transcript

  1. 1SPQBHBUF3FNPUF$POH VQEBUFTJOSFBMUJNF 2018/11/14 Firebase Summit 2018 ใࠂձ @Google Daiki Matsudate

    / @d_date
  2. %BJLJ.BUTVEBUF @d_date

  3. 1SPQBHBUF3FNPUF$POH VQEBUFTJOSFBMUJNF

  4. None
  5. /&8 3FNPUF$POHUSJHHFST

  6. functions.remoteConfig.onUpdate(versionMetadata => {});

  7. exports.showConfigDiff = functions.remoteConfig.onUpdate(versionMetadata => { return admin.credential.applicationDefault().getAccessToken() .then(accessTokenObj => {

    return accessTokenObj.access_token; }) .then(accessToken => { const currentVersion = versionMetadata.versionNumber; const templatePromises = []; templatePromises.push(getTemplate(currentVersion, accessToken)); templatePromises.push(getTemplate(currentVersion - 1, accessToken)); return Promise.all(templatePromises); }) .then(results => { const currentTemplate = results[0]; const previousTemplate = results[1]; const diff = jsonDiff.diffString(previousTemplate, currentTemplate); console.log(diff); return null; }).catch(error => { console.error(error); return null; }); });
  8. 1 4VCTDSJCFDMJFOUBQQ JOTUBODFTUPBO'$.UPQJD

  9. extension AppDelegate : MessagingDelegate { func messaging(_ messaging: Messaging, didReceiveRegistrationToken

    fcmToken: String) { Messaging.messaging().subscribe(toTopic: "PUSH_RC") { error in print("Subscribed to PUSH_RC topic") } } }
  10. 2 $SFBUFBGVODUJPOUPTFOEBO '$.QJOHPOUFNQMBUFVQEBUFT

  11. import * as functions from 'firebase-functions'; import * as admin

    from ‘firebase-admin'; admin.initializeApp(); exports.pushConfig = functions.remoteConfig.onUpdate(versionMetadata => { // Create FCM payload to send data message to PUSH_RC topic. const payload: admin.messaging.MessagingPayload = { data: { 'CONFIG_STATE': ‘STALE' } }; const options: admin.messaging.MessagingOptions = { contentAvailable: true } // Use the Admin SDK to send the ping via FCM. return admin.messaging() .sendToTopic('PUSH_RC', payload, options) .then(resp => { console.log(resp); return null; }); });
  12. { "aps" : { "content-available" : 1 }, }

  13. None
  14. None
  15. None
  16. None
  17. 3 4FUUIF3FNPUF$POH TUBUFPOUIFDMJFOU

  18. // Silent push notification func application(_ application: UIApplication, didReceiveRemoteNotification userInfo:

    [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { print("Entire message \(userInfo)") if let _ = userInfo["CONFIG_STATE"] as? String { UserDefaults.standard.set(true, forKey: "CONFIG_STALE") } completionHandler(.newData) }
  19. 4 'FUDIUIF3FNPUF$POH VQEBUFTPOBQQTUBSUVQ

  20. func fetchConfig() { welcomeLabel.text = remoteConfig[loadingPhraseConfigKey].stringValue var expirationDuration = 43200

    if remoteConfig.configSettings.isDeveloperModeEnabled || UserDefaults.standard.bool(forKey: "CONFIG_STALE") { expirationDuration = 0 UserDefaults.standard.set(false, forKey: "CONFIG_STALE") } remoteConfig.fetch(withExpirationDuration: TimeInterval(expirationDuration)) { (status, error) -> Void in let alertAction: UIAlertAction = .init(title: "OK", style: .default, handler: nil) if status == .success { print("Config fetched!") self.remoteConfig.activateFetched() } else { print("Config not fetched") print("Error: \(error?.localizedDescription ?? "No error available.")") } self.displayWelcome() } }
  21. %&.0

  22. "OBQQDBOGFUDIBNBYJNVNPGUJNFTJOBNJOVUF $BDIJOHBOEUISPUUMJOH

  23. ٥3FNPUF$POHUSJHHFST/08"7"*-"#-& ٥4JMFOU1VTI/PUJDBUJPOXJUIˎDPOUFOUBWBJMBCMFˏ ٥&OBCMFSFBMUJNFVQEBUFXJUI3FNPUF$POHBOE'$. 3FDBQ

  24. ٥1VTIJOH6QEBUFTUP:PVS"QQ4JMFOUMZ IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOVTFSOPUJDBUJPOTTFUUJOH@VQ@B@SFNPUF@OPUJDBUJPO@TFSWFS QVTIJOH@VQEBUFT@UP@ZPVS@BQQ@TJMFOUMZ ٥1SPQBHBUF3FNPUF$POHVQEBUFTJOSFBMUJNF IUUQTSFCBTFHPPHMFDPNEPDTSFNPUFDPOHQSPQBHBUFVQEBUFTSFBMUJNF 3FTPVSDFT

  25. None