58
47

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2020-08-17

はじめに

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
58
47
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
58
47

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?