Unity plugin to support the AppTrackingTransparency framework from Apple
MIT License
This repository contains a plugin to support the App Tracking Transparency framework for iOS in Unity 3D.
Introduced on iOS 14.0, Apple wants all developers that want to retrieve the IDFA for a user, to ask permission for it. If the user does not provide permission, an anonymous IDFA is provided instead (00000000-0000-0000-0000-000000000000
)
Starting from iOS 14.0, the API was made available for developers, but the restriction was not applied yet.
Starting from iOS 14.5, Apple started enforcing this rule, so all users have to give their permission to obtain the IDFA.
This plugin supports the following platforms:
Current version is v0.7.0
Here is a list of available options to install the plugin
Just add this line to the Packages/manifest.json
file of your Unity Project:
"dependencies": {
"com.lupidan.unity-apptrackingtransparency": "https://github.com/lupidan/unity-apptrackingtransparency.git?path=/com.lupidan.unity-apptrackingtransparency#v0.7.0"
}
To setup the plugin, you need to:
You can create and update the component in a MonoBehaviour of your choice. The MonoBehaviour can be a dedicated one, just for this manager, or a MonoBehaviour containing other managers.
Calling Update is required if you want to receive any asynchronous callbacks to be handled correctly inside Unity's update loop.
using AppTrackingTransparency;
using AppTrackingTransparency.Common;
...
public AppTrackingTransparencyHandler : MonoBehaviour
{
public IAppTrackingTransparencyManager AppTrackingTransparencyManager;
private void Start()
{
if (AppTrackingTransparencyModule.IsSupported)
{
this.AppTrackingTransparencyManager = AppTrackingTransparencyModule.CreateManager();
}
}
private void Update()
{
if (this.AppTrackingTransparencyManager != null)
{
this.AppTrackingTransparencyManager.Update();
}
}
}
Initially, the value is not determined. After requesting authorization, it becomes either Denied or Authorized.
this.AppTrackingTransparencyManager.TrackingAuthorizationStatus;
Starting from iOS 14.5, if the status is Authorized, you should get the user's IDFA. Otherwise, you should get an anonymous IDFA (00000000-0000-0000-0000-000000000000
)
In previous iOS versions you should get the user's IDFA.
this.AppTrackingTransparencyManager.Idfa;
You should request permission when the tracking authorization status is not determined.
β οΈ The callback won't execute if you are not calling Update on the AppTrackingTransparencyManager. Make sure you are periodically calling Update on it.
this.AppTrackingTransparencyManager.RequestTrackingAuthorization(authStatus =>
{
Debug.Log("Authorization status changed: " + authStatus);
});
To access the plugin configuration just go to the menu present in Assets -> AppTrackingTransparency -> Configuration You should see a window like this:
In this section you can control the current status of the editor implementation for the plugin.
The plugin offers automated options for post-processing on iOS. The first time you modify the iOS Build Settings, settings are saved in:
ProjectSettings/com.lupidan.unity-apptrackingtransparency/AppTrackingTransparencySettings.json
β οΈ This is a file you will want to commit to your repository, to keep your plugin configuration saved.
This section allow you to configure what parts of the automatic post-processing you want to have for your project.
Info.plist
file. When enabled, the auto post-processing will detect the current file and add the value in it. If disabled, you will have the option to specify the relative path for the Info.plist
file you want to modify.There is a folder inside the plugin code containing some samples. You can also import the sample code into your project by going to the Unity Package Manager, selecting the packages In Project, and selecting the AppTrackingTransparency for Unity package. You should see an option to import a sample: