コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】iOS ビルド時に Info.plist に Privacy - Tacking Usage Description(NSUserTrackingUsageDescription)を設定するエディタ拡張

概要

#if UNITY_IOS
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;

public static class Example
{
    [PostProcessBuild]
    private static void OnPostProcessBuild
    (
        BuildTarget buildTarget,
        string      pathToBuiltProject
    )
    {
        if ( buildTarget != BuildTarget.iOS ) return;

        var path  = pathToBuiltProject + "/Info.plist";
        var plist = new PlistDocument();

        plist.ReadFromFile( path );
        var root = plist.root;
        root.SetString( "NSUserTrackingUsageDescription", "ライチュウ" );
        plist.WriteToFile( path );
    }
}

#endif