Skip to content

Instantly share code, notes, and snippets.

@PSHalanYeats
Created January 9, 2021 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PSHalanYeats/1d8ba73ba03b6794fdb51960f87d6f8f to your computer and use it in GitHub Desktop.
Save PSHalanYeats/1d8ba73ba03b6794fdb51960f87d6f8f to your computer and use it in GitHub Desktop.
PostBuild IDFA
using UnityEditor;
using UnityEditor.Callbacks;
#if UNITY_IOS
using UnityEditor.iOS.Xcode;
#endif
using System.IO;
public class PostBuildStep
{
/// <summary>
/// Description for IDFA request notification
/// [sets NSUserTrackingUsageDescription]
/// </summary>
const string TrackingDescription =
"This identifier will be used to deliver personalized ads to you. ";
[PostProcessBuild(0)]
public static void OnPostprocessBuild(BuildTarget buildTarget, string pathToXcode)
{
if (buildTarget == BuildTarget.iOS)
{
AddPListValues(pathToXcode);
}
}
static void AddPListValues(string pathToXcode)
{
// Get Plist from Xcode project
string plistPath = pathToXcode + "/Info.plist";
// Read in Plist
PlistDocument plistObj = new PlistDocument();
plistObj.ReadFromString(File.ReadAllText(plistPath));
// set values from the root obj
PlistElementDict plistRoot = plistObj.root;
// Set value in plist
plistRoot.SetString("NSUserTrackingUsageDescription", TrackingDescription);
// save
File.WriteAllText(plistPath, plistObj.WriteToString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment