Search Unity

iOS 14 - Adding NSUserTrackingUsageDescription in the Info.plist file

Discussion in 'Unity Build Automation' started by affinixy, May 14, 2021.

  1. affinixy

    affinixy

    Joined:
    Nov 2, 2017
    Posts:
    13
    Hi, I just upgraded my UnityAds and iOS14 support.

    And I want to add NSUserTrackingUsageDescription into info.plist via Cloudbuild.

    This is my script,
    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEditor.Callbacks;
    3. #if UNITY_IOS
    4. using UnityEditor.iOS.Xcode;
    5. #endif
    6. using System.IO;
    7.  
    8. public class iOSATT
    9. {
    10. #if UNITY_IOS
    11.     // Set the IDFA request description:
    12.     const string k_TrackingDescription = "Your data will be used to provide you a better and personalized ad experience. And there are optional events that you can participate by registering with us.";
    13.  
    14.     [PostProcessBuild(0)]
    15.     public static void OnPostProcessBuild(BuildTarget buildTarget, string pathToXcode)
    16.     {
    17.         if (buildTarget == BuildTarget.iOS)
    18.         {
    19.             AddPListValues(pathToXcode);
    20.         }
    21.     }
    22.  
    23.     // Implement a function to read and write values to the plist file:
    24.     static void AddPListValues(string pathToXcode)
    25.     {
    26.         // Retrieve the plist file from the Xcode project directory:
    27.         string plistPath = pathToXcode + "/Info.plist";
    28.         PlistDocument plistObj = new PlistDocument();
    29.  
    30.  
    31.         // Read the values from the plist file:
    32.         plistObj.ReadFromString(File.ReadAllText(plistPath));
    33.  
    34.         // Set values from the root object:
    35.         PlistElementDict plistRoot = plistObj.root;
    36.  
    37.         // Set the description key-value in the plist:
    38.         plistRoot.SetString("NSUserTrackingUsageDescription", k_TrackingDescription);
    39.  
    40.         // Save changes to the plist:
    41.         File.WriteAllText(plistPath, plistObj.WriteToString());
    42.     }
    43. #endif
    44. }
    45.  
    And I added
    iOSATT.OnPostProcessBuild
    in CloudBuild>Advanced Options>Post-Export Method

    Is this correct way of implementing the key into info.plist via Cloudbuild?

    Because when I tried to call this
    ATTrackingStatusBinding.RequestAuthorizationTracking();
    I don't see any native dialog appearing on a newly installed game
     
    Last edited: May 15, 2021
  2. astanid

    astanid

    Joined:
    Apr 5, 2021
    Posts:
    145