@@ -13,6 +13,7 @@ import KakaoSDKCommon
1313import FirebaseCore
1414import FirebaseFirestore
1515import FirebaseAuth
16+ import FirebaseRemoteConfig
1617
1718@main
1819class AppDelegate : UIResponder , UIApplicationDelegate {
@@ -38,6 +39,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3839 func application( _ application: UIApplication , didFinishLaunchingWithOptions launchOptions: [ UIApplication . LaunchOptionsKey : Any ] ? ) -> Bool {
3940
4041 FirebaseApp . configure ( )
42+ setRemoteConfig ( )
43+
4144 NMFAuthManager . shared ( ) . clientId = Config . naverMapClientId
4245 KakaoSDK . initSDK ( appKey: Config . kakaoNativeAppKey)
4346
@@ -58,3 +61,58 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
5861 // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
5962 }
6063}
64+
65+ extension AppDelegate {
66+ func setRemoteConfig( ) {
67+ let remoteConfig = RemoteConfig . remoteConfig ( )
68+ let settings = RemoteConfigSettings ( )
69+
70+ /// 개발 중에는 0으로 설정
71+ settings. minimumFetchInterval = 86400 // 24hour
72+ remoteConfig. configSettings = settings
73+
74+ remoteConfig. fetch ( ) { ( status, error) -> Void in
75+ if status == . success {
76+ remoteConfig. activate ( ) { ( changed, error) in
77+ guard let info = Bundle . main. infoDictionary,
78+ let currentVersion = info [ " CFBundleShortVersionString " ] as? String ,
79+ let identifier = info [ " CFBundleIdentifier " ] as? String ,
80+ let storeVersion = remoteConfig [ " iOS_current_market_version " ] . stringValue
81+ else { return }
82+
83+ if currentVersion. compare ( storeVersion, options: . numeric) == . orderedAscending {
84+ self . showUpdateAlert ( )
85+ }
86+ }
87+ } else {
88+ print ( " Error: \( error? . localizedDescription ?? " No error available. " ) " )
89+ }
90+ }
91+ }
92+
93+ func showUpdateAlert( ) {
94+ DispatchQueue . main. sync {
95+ let alert = UIAlertController (
96+ title: " 업데이트 알림 " ,
97+ message: " 새로운 기능이 추가된 'Runnect'의 최신 버전을 만나보세요! \n 지금 바로 업데이트하고 개선된 사용자 경험을 즐겨보세요. " ,
98+ preferredStyle: . alert
99+ )
100+
101+ let updateAction = UIAlertAction ( title: " 업데이트 링크 " , style: . default) { _ in
102+ let url = " itms-apps://itunes.apple.com/app/1663884202 "
103+ if let url = URL ( string: url) , UIApplication . shared. canOpenURL ( url) {
104+ if #available( iOS 13 . 0 , * ) {
105+ UIApplication . shared. open ( url, options: [ : ] , completionHandler: nil )
106+ } else {
107+ UIApplication . shared. openURL ( url)
108+ }
109+ }
110+ }
111+
112+ alert. addAction ( updateAction)
113+ if let vc = UIApplication . shared. keyWindow? . rootViewController {
114+ vc. present ( alert, animated: true , completion: nil )
115+ }
116+ }
117+ }
118+ }
0 commit comments