From 675842e01a80a15ebce80a79bf2b5cac2bab542b Mon Sep 17 00:00:00 2001 From: Mijin Jeon Date: Sun, 3 Feb 2019 02:53:03 +0900 Subject: [PATCH] Feat: Implement firebase remote control #75 - Implement basic feature of firebase remote control - Add error message field in slack webhook --- MartHoliday/MartHoliday/AppDelegate.swift | 16 +++++++++++++++ .../ReachabilityViewController.swift | 4 ++-- MartHoliday/Podfile | 2 ++ MartHoliday/Podfile.lock | 20 ++++++++++++++++++- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/MartHoliday/MartHoliday/AppDelegate.swift b/MartHoliday/MartHoliday/AppDelegate.swift index b51bb01..b53fb51 100644 --- a/MartHoliday/MartHoliday/AppDelegate.swift +++ b/MartHoliday/MartHoliday/AppDelegate.swift @@ -28,6 +28,22 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD setNavigationBar() FirebaseApp.configure() + let remoteConfig = RemoteConfig.remoteConfig() + remoteConfig.configSettings = RemoteConfigSettings(developerModeEnabled: true) + + remoteConfig.fetch(withExpirationDuration: TimeInterval(3600)) { (status, error) -> Void in + if status == .success { + remoteConfig.activateFetched() + // remoteConfig에서 강제업데이트 옵션 조회 + if remoteConfig["forced_update"].boolValue { + + } + } else { + // 슬랙에 웹훅으로 알림 + SlackWebhook.fire(brokenUrl: nil, errorMessage: "[Firebase remote config] \(error?.localizedDescription ?? "No error available.")") + } + } + application.applicationIconBadgeNumber = 0 if #available(iOS 10.0, *) { diff --git a/MartHoliday/MartHoliday/ViewController/ReachabilityViewController.swift b/MartHoliday/MartHoliday/ViewController/ReachabilityViewController.swift index 5464047..fdfef8a 100644 --- a/MartHoliday/MartHoliday/ViewController/ReachabilityViewController.swift +++ b/MartHoliday/MartHoliday/ViewController/ReachabilityViewController.swift @@ -52,14 +52,14 @@ class SlackWebhook { case headerField = "Content-Type" } - class func fire(brokenUrl: URL?) { + class func fire(brokenUrl: URL?, errorMessage: String? = nil) { guard let url = URL(string: SlackWebhook.Keyword.url.rawValue) else { return } var request = URLRequest(url: url) request.httpMethod = "POST" request.addValue(SlackWebhook.Keyword.dataType.rawValue, forHTTPHeaderField: SlackWebhook.Keyword.headerField.rawValue) var payload: [String:String] = [:] - payload["text"] = ">>>문제가 터졌다:bomb:\n얼른고쳐라 닝겐\nURL: \(brokenUrl?.absoluteString ?? "none")" + payload["text"] = ">>>문제가 터졌다:bomb:\n얼른고쳐라 닝겐\nURL: \(brokenUrl?.absoluteString ?? "none")\n에러메시지: \(errorMessage ?? "none")" payload["icon_emoji"] = self.selectRandomEmoji() guard let httpBody = try? JSONSerialization.data(withJSONObject: payload, options: []) else { return } diff --git a/MartHoliday/Podfile b/MartHoliday/Podfile index 807f049..2a3dd03 100644 --- a/MartHoliday/Podfile +++ b/MartHoliday/Podfile @@ -6,6 +6,8 @@ def shared_pods pod 'Firebase/Database' pod 'Firebase/Messaging' pod 'Firebase/Storage' + pod 'Firebase/RemoteConfig' + pod 'ReachabilitySwift' pod 'NVActivityIndicatorView' pod 'Toaster' diff --git a/MartHoliday/Podfile.lock b/MartHoliday/Podfile.lock index ae18e09..b7da922 100644 --- a/MartHoliday/Podfile.lock +++ b/MartHoliday/Podfile.lock @@ -10,9 +10,15 @@ PODS: - Firebase/Messaging (5.2.0): - Firebase/CoreOnly - FirebaseMessaging (= 3.0.2) + - Firebase/RemoteConfig (5.2.0): + - Firebase/Core + - FirebaseRemoteConfig (= 3.0.0) - Firebase/Storage (5.2.0): - Firebase/CoreOnly - FirebaseStorage (= 3.0.0) + - FirebaseABTesting (2.0.0): + - FirebaseCore (~> 5.0) + - Protobuf (~> 3.5) - FirebaseAnalytics (5.0.1): - FirebaseCore (~> 5.0) - FirebaseInstanceID (~> 3.0) @@ -30,6 +36,13 @@ PODS: - FirebaseInstanceID (~> 3.0) - GoogleToolboxForMac/Logger (~> 2.1) - Protobuf (~> 3.1) + - FirebaseRemoteConfig (3.0.0): + - FirebaseABTesting (~> 2.0) + - FirebaseAnalytics (~> 5.0) + - FirebaseCore (~> 5.0) + - FirebaseInstanceID (~> 3.0) + - "GoogleToolboxForMac/NSData+zlib (~> 2.1)" + - Protobuf (~> 3.5) - FirebaseStorage (3.0.0): - FirebaseCore (~> 5.0) - GTMSessionFetcher/Core (~> 1.1) @@ -56,6 +69,7 @@ DEPENDENCIES: - Firebase/Core - Firebase/Database - Firebase/Messaging + - Firebase/RemoteConfig - Firebase/Storage - NVActivityIndicatorView - ReachabilitySwift @@ -64,11 +78,13 @@ DEPENDENCIES: SPEC REPOS: https://github.com/cocoapods/specs.git: - Firebase + - FirebaseABTesting - FirebaseAnalytics - FirebaseCore - FirebaseDatabase - FirebaseInstanceID - FirebaseMessaging + - FirebaseRemoteConfig - FirebaseStorage - GoogleToolboxForMac - GTMSessionFetcher @@ -81,11 +97,13 @@ SPEC REPOS: SPEC CHECKSUMS: Firebase: 25ed0412036d7d008568d1fb4d2e9d81ea8a0a2c + FirebaseABTesting: 1f50b8d50f5e3469eea54e7463a7b7fe221d1f5e FirebaseAnalytics: b3628aea54c50464c32c393fb2ea032566e7ecc2 FirebaseCore: a3c87242451633fff8490183898075ce77d168d2 FirebaseDatabase: 482bad9c2abd422bb2321194fb8c937e67426a89 FirebaseInstanceID: 05d779cbb97bd5bd5c51a38a903fc9cfe1b2454a FirebaseMessaging: 6894b8fe0a0cf26c3b13dad729f1131654ae0bdb + FirebaseRemoteConfig: 3c57e4644bd6976b671ae0b725cd709f198bd1f5 FirebaseStorage: 7ca4bb7b58a25fa647b04f524033fc7cb7eb272b GoogleToolboxForMac: 91c824d21e85b31c2aae9bb011c5027c9b4e738f GTMSessionFetcher: 5fa5b80fd20e439ef5f545fb2cb3ca6c6714caa2 @@ -96,6 +114,6 @@ SPEC CHECKSUMS: ReachabilitySwift: 6849231cd4e06559f3b9ef4a97a0a0f96d41e09f Toaster: a6c9532de1ded8105e77376f7dffeb2e12b46dbb -PODFILE CHECKSUM: 80709dae3cd8a1ab79a575af5b1dabf4008acd4a +PODFILE CHECKSUM: 5f58e9e21d7cd4a9eee7d79e964ed874290e1aea COCOAPODS: 1.5.3