티스토리 뷰

반응형

안녕하세요 오늘은 APP 버전을 가져오는 방법을 기술하겠습니다.

 

이번에 개발하면서 처음 앱 실행시 앱에 버전과 안맞으면 업데이트를 하는 기능을 해야되서 

 

개발하게 되었는데요

현제 버전과 최소버전을 두개를 비교해야되는데 

 

                let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String
                let bundleVersion = Bundle.main.infoDictionary?["CFBundleVersion"] as! String
                print(version)
                if (version == VersionCode) == true {
                    self.stepProc()
                }else {
                    let iBundle = Int(bundleVersion)
                    let iMinVer = Int(MinVersionCode)
                    if iBundle! <= iMinVer!{
                        appDelegate().showAlert(title: "알림", mainMsg: "업데이트 이후에 사용이 가능합니다.", ok: "이동", action1: { (UIAlertAction) in
                            print("앱설치로 강제 이동 이동되야됨 취소없음")
                            
                        }, cancel: "", action2: nil)
                    }else {
                        appDelegate().showAlert(title: "알림", mainMsg: "업데이트된 버전이 있습니다.", ok: "확인", action1: { (UIAlertAction) in
                             print("업데이트를 위해 스토어로 이동")
                        }, cancel: "취소", action2: { (UIAlertAction) in
                            print("취소하고 진행")
                        })
                    }
                }

위의 코드를 설명하자면

1) Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String

2) Bundle.main.infoDictionary?["CFBundleVersion"] as! String

 

1번은 프로젝트의  Version을 가져오는거고 

2번은 Bulid 값을 가져오는 방법입니다.

 

저는 1번은 업데이트 버전을 알리기 위한 용도로 사용하기 위해서 가져왔고

2번은 강제 업데이트를 위해서 선언을 하였습니다.

 

xCode에서 버전 변경은 아래 이미지에서 변경하였습니다.

 

XCode 버전 

 

반응형
댓글