[objc/swift] 앱버전, 버전코드 정보 가져오기

천현철·2021년 6월 28일
0

iOS

목록 보기
42/51
post-custom-banner

objc:

+ (NSString*) getAppVersionName
{
    return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
}

+ (NSString*) getAppBuildVersionCode
{
    return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
}

swift:

var version: String? {
    guard let dictionary = Bundle.main.infoDictionary,
        let version = dictionary["CFBundleShortVersionString"] as? String,
        let build = dictionary["CFBundleVersion"] as? String else {return nil}
    
    let versionAndBuild: String = "vserion: \(version), build: \(build)"
    return versionAndBuild
}

출처
https://stackoverflow.com/questions/24501288/getting-version-and-build-information-with-swift

profile
기도하지말고 행동하라
post-custom-banner

0개의 댓글