LoginSignup
36
20

More than 5 years have passed since last update.

iOS10から必要になったユーザデータにアクセスする為に表示する文言をローカライズする

Last updated at Posted at 2016-10-02

⛔️iOS10からユーザでにアクセスする際には理由を明示する

iOS 10 introduces several changes and additions that help you improve the security of your code and maintain the privacy of user data. To learn more about these items, see https://developer.apple.com/security/.

概要はこちらの記事からどうぞ🔗

実際にはplistファイルのValuestringとして文言を設定します。
こちらの表のXcode name でPrivacyの表記があるモノですね。

ただInfo.plistに設定してしまうと、ローカライズが出来ません。
(ここで設定しているものが優先的に表示される為)

なので、Info.plistの設定をローカライズする必要があります。

🌐plistをローカライズする

サンプルを作成した環境は以下となります。

  • macOS 10.11.6
  • Xcode8.0
  • Swift3

やり方

Localized values are not stored in the Info.plist file itself. Instead, you store the values for a particular localization in a strings file with the name InfoPlist.strings. You place this file in the same language-specific project directory that you use to store other resources for the same localization. The contents of the InfoPlist.strings file are the individual keys you want localized and the appropriately translated value. The routines that look up key values in the Info.plist file take the user’s language preferences into account and return the localized version of the key (from the appropriate InfoPlist.strings file) when one exists. If a localized version of a key does not exist, the routines return the value stored in the Info.plist file.

About Information Property List Files

ドキュメントにあるままなので、問題ないかと思いますが、

  1. InfoPlist.stringファイルを作成
  2. 作成したファイルをローカライズ

という流れになります。
簡単にローカライズファイルの作成方法を説明すると、

File -> New -> File... を選択

Strings File を選択

InfoPlist という名前で保存

これでInfoPlist.strings が作成されます。

次にそのファイルをローカライズしていきます。
効率の良いやり方、ツールなどあれば是非教えてください。

あとは、このファイルをローカライズしてきます。
プロジェクトファイルを選択した状態で、Info タブの Localizations の"+"を選択して、対応した言語を選択します。

例えば、フォトライブラリーにアクセスする時は

InfoPlist.strings
"NSPhotoLibraryUsageDescription" = "アップロードする画像を選択するために必要です";

といって感じで設定すれば、OKです。
対応させる言語なんて1つしかないよという場合は

Info.plistの設定に“Privacy - Photo Library Usage Description” を追加するだけです。

🔚終わりに

また、冒頭でも書いたように Info.plist でも InfoPlist.strings でも設定する事ができますが、その場合はローカライズファイルの内容は無視されてInfo.plistの内容が優先されてしまいますので注意してください😱

間違いあったら教えていただけるとうれしいです。
よろしくお願いいたします🙏

💬余談

因みに、Androidではこんな感じにやるみたいです。

ぱっと見、Android Studioのエコシステム上で編集も出来るのがいいなと思いました。

🔗Refs

2017年1月25日 追記

  • Apple申請時にもし、plistに該当の項目の記述がなかった場合はメールが届き、iTunes connectにて、バイナリはアップロードできますが、ビルドの欄に該当のバイナリが表示されません。
  • リジェクトされる旨の投稿もあるようなのですが、再現手順(無いにこした事はないですが)がわからなかったです><
36
20
2

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
36
20