Skip to content

Commit

Permalink
Feat: Implement firebase remote control #75
Browse files Browse the repository at this point in the history
- Implement basic feature of firebase remote control
- Add error message field in slack webhook
  • Loading branch information
jinios committed Feb 2, 2019
1 parent a7de2b9 commit 675842e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
16 changes: 16 additions & 0 deletions MartHoliday/MartHoliday/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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, *) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 2 additions & 0 deletions MartHoliday/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
20 changes: 19 additions & 1 deletion MartHoliday/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -56,6 +69,7 @@ DEPENDENCIES:
- Firebase/Core
- Firebase/Database
- Firebase/Messaging
- Firebase/RemoteConfig
- Firebase/Storage
- NVActivityIndicatorView
- ReachabilitySwift
Expand All @@ -64,11 +78,13 @@ DEPENDENCIES:
SPEC REPOS:
https://github.com/cocoapods/specs.git:
- Firebase
- FirebaseABTesting
- FirebaseAnalytics
- FirebaseCore
- FirebaseDatabase
- FirebaseInstanceID
- FirebaseMessaging
- FirebaseRemoteConfig
- FirebaseStorage
- GoogleToolboxForMac
- GTMSessionFetcher
Expand All @@ -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
Expand All @@ -96,6 +114,6 @@ SPEC CHECKSUMS:
ReachabilitySwift: 6849231cd4e06559f3b9ef4a97a0a0f96d41e09f
Toaster: a6c9532de1ded8105e77376f7dffeb2e12b46dbb

PODFILE CHECKSUM: 80709dae3cd8a1ab79a575af5b1dabf4008acd4a
PODFILE CHECKSUM: 5f58e9e21d7cd4a9eee7d79e964ed874290e1aea

COCOAPODS: 1.5.3

0 comments on commit 675842e

Please sign in to comment.