47
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

updated at

Organization

iOSアプリのバージョンを取得する

はじめに

Objective-CとSwiftでiOSアプリのバージョンを取得する方法です。
下図の赤枠で囲ったVersionの値を取得します。

xcode.jpg

Objective-C

Objective-Cの場合は次のようになります。

sample1.m
NSString *version = [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleShortVersionString"];

または

sample2.m
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];

と書くことができます。

ビルド(Build)を取得する場合は、CFBundleVersionを指定します。

sample3.m
NSString *build = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];

Swift

Swiftの場合は次のようになります。

sample.swift
let version: String! = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") as String

let build: String! = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleVersion") as String
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
47
Help us understand the problem. What are the problem?