LoginSignup
7
10

More than 3 years have passed since last update.

CocoaPodsでOSSライブラリのライセンス表記を自動生成する

Last updated at Posted at 2018-07-19

OSSライブラリを利用していればライセンス表記は必須ですが、ライブラリが増えるほどライセンス表示も追加しないといけないので手動管理は中々大変。

CocoaPodsでライセンス表記を自動生成できるとのこと。

環境

  • Xcode 9.4.1
  • CocoaPods 1.5.3
  • プロジェクトにCocoaPodsは導入済み

ライセンスの表記箇所

ライセンスの表記箇所はiPhoneの設定アプリ(歯車のやーつ)にあるアプリページに設置する。

<確認方法>
設定アプリを起動 > 起動直後のページをスクロールするとアプリ名の一覧が出てくるので対象のアプリを選択

Xcode上でacknowledgementファイルを作成して設定すればこの場所にライセンスの表示を設置することが可能。
今回はCocoaPodsで自動的にこのファイルを生成する。

マクドナルド、ケンタッキー、Coincheckのアプリなんかもここにライセンス表示を設置してる模様。

Settings.bundleを作成する

  • Xcode起動 > New File… > Settings Bundle

Root.plistを編集する

作成したSettings.bundle内にあるRoot.plistを公式ドキュメントに沿って編集する

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>StringsTable</key>
        <string>Root</string>
        <key>PreferenceSpecifiers</key>
        <array>
            <dict>
                <key>Type</key>
                <string>PSChildPaneSpecifier</string>
                <key>Title</key>
                <string>Acknowledgements</string>
                <key>File</key>
                <string>Acknowledgements</string>
            </dict>
        </array>
    </dict>
</plist>

Podfileを編集

以下を追記する。

Pathは環境に合わせて書き換える(Podfileからの相対Path)。
例として、プロジェクト名がHoge、Settings.bundleをHogeプロジェクトのHogeディレクトリ直下に置いた場合。

post_install do | installer |
  require 'fileutils'
  FileUtils.cp_r('Pods/Target Support Files/Pods-Hoge/Pods-Hoge-acknowledgements.plist', 'Hoge/Settings.bundle/Acknowledgements.plist', :remove_destination => true)
end

変更を反映

$ pod update

確認

Settings.bundle以下にAcknowledgements.plistが書き出されて入ればOK
あとはビルドして設定アプリにライセンス表記があるか確認

7
10
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
7
10