|
1 | 1 | import Foundation |
2 | 2 | import FirebaseWrapper |
3 | 3 | import FirebaseRemoteConfig |
4 | | -import SwiftBoost |
| 4 | +// import SwiftBoost |
5 | 5 |
|
6 | 6 | extension FirebaseWrapper { |
7 | 7 |
|
8 | 8 | public class RemoteConfig { |
9 | 9 |
|
10 | | - public static func configure(updatedHandler: (() -> Void)? = nil) { |
11 | | - debug("FirebaseWrapper: RemoteConfig configure") |
| 10 | + public static func configure( |
| 11 | + defaults: [String : NSObject]? = nil, |
| 12 | + updatedHandler: (() -> Void)? = nil |
| 13 | + ) { |
| 14 | + // debug("FirebaseWrapper: RemoteConfig configure") |
12 | 15 | shared.updatedHandler = updatedHandler |
13 | 16 |
|
14 | 17 | let settings = RemoteConfigSettings() |
15 | 18 | settings.minimumFetchInterval = 0 |
16 | 19 | shared.remoteConfig.configSettings = settings |
| 20 | + shared.remoteConfig.setDefaults(defaults ?? [:]) |
17 | 21 |
|
18 | | - debug("FirebaseWrapper: RemoteConfig fetchAndActivate") |
19 | | - shared.remoteConfig.fetchAndActivate() |
20 | | - shared.remoteConfig.fetch { configUpdate, getError in |
21 | | - guard getError == nil else { |
22 | | - error("FirebaseWrapper: RemoteConfig initial get with error, " + (getError?.localizedDescription ?? .empty)) |
23 | | - return |
| 22 | + // debug("FirebaseWrapper: RemoteConfig fetchAndActivate") |
| 23 | + shared.remoteConfig.fetch { updateStatus, getError in |
| 24 | + switch updateStatus { |
| 25 | + case .success: |
| 26 | + activateNewConfig() |
| 27 | + case .failure, .noFetchYet, .throttled: |
| 28 | + //error("FirebaseWrapper: RemoteConfig initial get with error, " + (getError?.localizedDescription ?? .empty)) |
| 29 | + break |
| 30 | + @unknown default: |
| 31 | + break |
24 | 32 | } |
25 | | - activateNewConfig() |
26 | 33 | } |
27 | 34 |
|
28 | 35 | shared.remoteConfig.addOnConfigUpdateListener { configUpdate, listnerError in |
29 | 36 | guard listnerError == nil else { |
30 | | - error("FirebaseWrapper: RemoteConfig got update in listner with error, " + (listnerError?.localizedDescription ?? .empty)) |
| 37 | + //error("FirebaseWrapper: RemoteConfig got update in listner with error, " + (listnerError?.localizedDescription ?? .empty)) |
31 | 38 | return |
32 | 39 | } |
33 | | - debug("FirebaseWrapper: RemoteConfig activate after got new in listner") |
| 40 | + // debug("FirebaseWrapper: RemoteConfig activate after got new in listner") |
34 | 41 | activateNewConfig() |
35 | 42 | } |
36 | 43 | } |
37 | 44 |
|
38 | 45 | private static func activateNewConfig() { |
39 | 46 | shared.remoteConfig.activate { changed, activateError in |
40 | 47 | guard activateError == nil else { |
41 | | - error("FirebaseWrapper: RemoteConfig can't activate after got new in listner, " + (activateError?.localizedDescription ?? .empty)) |
| 48 | + // error("FirebaseWrapper: RemoteConfig can't activate after got new in listner, " + (activateError?.localizedDescription ?? .empty)) |
42 | 49 | return |
43 | 50 | } |
44 | 51 |
|
45 | 52 | shared.updatedHandler?() |
46 | | - NotificationCenter.default.post(name: .firebaseWrapperRemoteConfigUpdated) |
| 53 | + // NotificationCenter.default.post(name: .firebaseWrapperRemoteConfigUpdated) |
47 | 54 | } |
48 | 55 | } |
49 | 56 |
|
|
0 commit comments