1. firebase 에 ios 앱 추가
2. remote config 에 매개변수 추가
"title" : "title"
"title2" : "title2"
3. GoogleService-Info.plist 다운로드 후 xcode 프로젝트에 추가
4. podfile에 'Firebase/Core' , 'Firebase/RemoteConfig' 추가 후 install
5. 코드 추가 << Swift 5 기준 >>
//firebase import
import Firebase
...
//remote config에 적용되어 있는 키 값
var titleValue = ""
var title2Value = ""
...
//remote config 에 저장되어있는 값 가져오기
func updateRemoteConfigValues(){
titleValue = RemoteConfig.remoteConfig().configValue(forKey:"title").stringValue ?? ""
title2Value = RemoteConfig.remoteConfig().configValue(forKey:"title2").stringValue ?? ""
print("remote config key : title , value : \(titleValue)")
print("remote config key : title2 , value : \(title2Value)")
}
//remote config에 default 값 설정
func setupRemoteConfigDefaults(){
let defaultValues = [
"title" = "default" as NSObject,
"title2" = "default2" as NSObject
]
RemoteConfig.remoteConfig().setDefaults(defaultValues)
}
//remote config 가져오기
func fetchRemoteConfig(){
let debugSettings = RemoteConfigSettings.init(developerModeEnabled: true)
RemoteConfig.remoteConfig().configSettings = debugSettings
//remote config 에서 매개변수 값 가져오기
RemoteConfig.remoteConfig().fetch(withExpirationDuration: 0) { [unowned self] (status, error) in
guard error == nil else{
print("remote config error : \(error)")
return
}
//가져온 매개변수 값 앱에 적용
RemoteConfig.remoteConfig().activateFetched()
self.updateRemoteConfigValues()
}
}
...
override func viewDidLoad(){
super.viewDidLoad()
setupRemoteConfigDefaults()
fetchRemoteConfig()
...
}
'iOS - Swift' 카테고리의 다른 글
[스위프트/Swift] duplicate symbols for architecture arm64 (0) | 2019.12.30 |
---|---|
[스위프트/Swift] /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby: bad interpreter: No such file or directory (0) | 2019.10.29 |
[스위프트/Swift] UILabel 부분 속성 변경 (0) | 2019.10.23 |
[스위프트/Swift] 커스텀 폰트 적용 오류 (0) | 2019.10.23 |
[스위프트/Swift] 현재 시간 출력 (0) | 2018.10.25 |