Skip to content

Instantly share code, notes, and snippets.

@yasuyuki-kamata
Last active June 29, 2021 03:37
Show Gist options
  • Save yasuyuki-kamata/a92280ec2cad217ba930f2033ab0b350 to your computer and use it in GitHub Desktop.
Save yasuyuki-kamata/a92280ec2cad217ba930f2033ab0b350 to your computer and use it in GitHub Desktop.
XcodeプロジェクトのInfo.plistにATTダイアログ用の説明文のkey-valueを追加するポストプロセスビルドのスクリプト
/// PostBuildStep.cs
#if UNITY_IOS
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
using System.IO;
public class PostBuildStep {
// IDFA取得のためのトラッキング許可の説明文をセットします:
const string k_TrackingDescription =
"私たちは、お客様が利用するアプリやデバイス、地域に基づいて、" +
"お客様にとって最も興味のあるアプリや製品の広告を表示するようにしています。";
[PostProcessBuild(0)]
public static void OnPostProcessBuild(
BuildTarget buildTarget, string pathToXcode)
{
if (buildTarget == BuildTarget.iOS) {
AddPListValues(pathToXcode);
}
}
// plistファイルに値を読み書きする関数を実装します:
static void AddPListValues(string pathToXcode) {
// Xcodeプロジェクトのディレクトリからplistファイルを取得します:
string plistPath = pathToXcode + "/Info.plist";
PlistDocument plistObj = new PlistDocument();
// plistファイルから値を読み込みます:
plistObj.ReadFromString(File.ReadAllText(plistPath));
// ルートオブジェクトの値をセットします:
PlistElementDict plistRoot = plistObj.root;
// plistの中に説明文のkey-valueをセットします:
plistRoot.SetString("NSUserTrackingUsageDescription",
k_TrackingDescription);
// plistファイルに変更を保存します:
File.WriteAllText(plistPath, plistObj.WriteToString());
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment