LoginSignup
83
74

More than 5 years have passed since last update.

CocoaPodsでカスタムコンフィギュレーションを使う

Last updated at Posted at 2014-10-11

コンフィギュレーションを分けるとリンクするライブラリやフラグを切り替えることが出来るので、例えばデバッグ時のみビューインスペクタライブラリをリンクしたり、フィードバック用のボタンを追加する、といったことが可能です。

Xcodeでプロジェクトを作成すると自動的にDebug, Releaseという2つのコンフィギュレーションが作成されるのですが、これ以外のコンフィギュレーションをCocoaPodsから使用するには少し追加手順が必要だったのでメモ書きです。

要件

  • Adhoc用のコンフィギュレーションを追加したい
  • Adhoc用コンフィギュレーションでは、TestFlightのライブラリをリンクしたい

手順

コンフィギュレーションの追加

プロジェクトのInfoタブから新しいコンフィギュレーションを追加します。AdhocはRelease版とほぼ同等なので、Releaseコンフィギュレーションをコピーする形で作成します。

kobito.1412997661.362356.png

コンフィギュレーションファイルの追加

次に、Adhoc用のコンフィギュレーションファイルを追加します。XcodeからNew Fileを選択して、iOS -> Other -> Configuration settings fileを選択します。

kobito.1412996835.599144.png

ファイル名は *Config.adhoc.xcconfig * など適当な名前にします。

kobito.1412997770.321065.png

Podfileの作成

以下のPodfileは例です。 TestFlightFeedback というフィードバックフォーム用のライブラリを、Debug, Adhocコンフィギュレーションに追加します。また、SparkInspector(ビューインスペクタライブラリ)をDebugコンフィギュレーションに追加します。

Podfile
platform :ios, "7.0"

source 'https://github.com/CocoaPods/Specs.git'

inhibit_all_warnings!

pod "TestFlightSDK", :configuration => ["Debug", "Adhoc"]
pod "TestFlightFeedback", :configuration => ["Debug", "Adhoc"]
pod "SparkInspector", :configuration => ["Debug"]

ライブラリのインストール

$ pod install
Analyzing dependencies
Downloading dependencies
Installing SparkInspector (1.3.0)
Installing TestFlightFeedback (2.1.1)
Installing TestFlightSDK (3.0.2)
Generating Pods project
Integrating client project

[!] From now on use `example.xcworkspace`.

[!] CocoaPods did not set the base configuration of your project because because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target example` to `Pods/Target Support Files/Pods/Pods.adhoc.xcconfig` or include the `Pods/Target Support Files/Pods/Pods.adhoc.xcconfig` in your build configuration.

インストール後、 Pods/Target Support Files/Pods ディレクトリにコンフィギュレーションファイルが追加されます。次のファイルが作成されることを確認しましょう。

  • Pods.debug.xcconfig
  • Pods.adhoc.xcconfig
  • Pods.release.xcconfig

Adhocコンフィギュレーションの選択と、コンフィギュレーションファイルの編集

Adhocコンフィギュレーションの場合には、Adhoc用のコンフィギュレーションファイルを使用します。プロジェクトのInfoタブからAdhocのコンフィギュレーションを選択し、プルダウンメニュー内のConfig.adhocを選択しましょう。

kobito.1412997980.341599.png

pod install時に表示されているように、CocoaPodsはDebug, Release以外のコンフィギュレーションを取り扱わないので、カスタムコンフィギュレーションを使用する場合には自分でファイルを作成してincludeする必要があります。

先ほど追加した Config.adhoc.xcconfig を選択して、ファイルに以下のテキストを追加します。

#include "Pods/Target Support Files/Pods/Pods.adhoc.xcconfig"

このように書いておくと、カスタムコンフィギュレーションでもCococaPodsを使用することが出来るようになります。


参考

83
74
0

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
83
74