앱을 출시하고, 긴급하게 수정해야할 사항이 생길 때 앱 수정을 하고 심사를 받아서 배포를 하기 위해서는 너무 오랜 시간이 걸린다.
이때 우리는 Firebase의 Romote Config를 사용해서 앱을 수정할 수 있다.
Remote config
에 들어간다. override func viewDidLoad() {
super.viewDidLoad()
remoteConfig = RemoteConfig.remoteConfig()
let setting = RemoteConfigSettings()
setting.minimumFetchInterval = 0 //test를 위해서 패치되는 인터벌 얼만큼?
remoteConfig?.configSettings = setting //setting값 전달
remoteConfig?.setDefaults(fromPlist: "RemoteConfigDefaultsPropertyList")
}
func getNotice(){
guard let remoteConfig = remoteConfig else {return}
remoteConfig.fetch{ [weak self] status, _ in
if status == .success{
remoteConfig.activate()
} else{
print("ERROR: Config not fetched")
}
guard let self = self else { return }
if !self.isNoticeHeidden(remoteConfig){
let noticeVC = NoticeViewController(nibName: "NoticeViewController", bundle: nil)
noticeVC.modalPresentationStyle = .custom
noticeVC.modalTransitionStyle = .crossDissolve
let title = (remoteConfig["title"].stringValue ?? "").replacingOccurrences(of: "\\n", with: "\n")
let detail = (remoteConfig["detail"].stringValue ?? "").replacingOccurrences(of: "\\n", with: "\n")
let date = (remoteConfig["date"].stringValue ?? "").replacingOccurrences(of: "\\n", with: "\n")
noticeVC.noticeContents = (title: title, detail: detail, date: date)
self.present(noticeVC, animated: true, completion: nil)
} else{
self.showEventAlert()
}
}
}
viewWillAppear()
에 들어갈 함수를 만들어준다.규모가 작은 앱을 운영을 할 때는 데이터를 기반으로 사용자의 니즈를 파악하기가 힘들다.
이때 A/B Testing은 비교군의 데이터와 실험군의 데이터를 다르게 하여 사용자에게 보여주고, 사용자의 행동을 파악하여 쉽게 사용자의 니즈를 파악할 수 있도록 해준다.
사용자에게 두가지 alert를 보여주고, 어떤 alert창이 더 확인을 많이 누르는지를 볼 수 있는 코드를 작성해볼 것이다.
//AB test
extension ViewController{
func showEventAlert(){
guard let remoteConfig = remoteConfig else {return}
remoteConfig.fetch{ [weak self] status, _ in
if status == .success{
remoteConfig.activate()
} else {
print("Config not fetched")
}
let message = remoteConfig["message"].stringValue ?? ""
let confirmAction = UIAlertAction(title: "확인하기", style: .default){ _ in
Analytics.logEvent("promotion_alert", parameters: nil)
}
let cancelAction = UIAlertAction(title: "취소", style: .cancel)
let alertController = UIAlertController(title: "깜짝이벤트", message: message, preferredStyle: .alert)
alertController.addAction(confirmAction)
alertController.addAction(cancelAction)
self?.present(alertController, animated: true)
}
}
}
confirmAction
프로퍼티의 클로저에 Analytics.logEvent
를 통해 confirmAction
이 일어날 경우 우리는 firebase에서 사용자의 행동을 파악할 수 있다.