Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

App Tracking Transparency framework on Unity

Discussion in 'iOS and tvOS' started by IvyKun, Sep 1, 2020.

  1. IvyKun

    IvyKun

    Joined:
    Sep 28, 2013
    Posts:
    132
    Is there any news on when will Unity will add an implementation for the app tracking transparency framework?
    I can't find anything in the documentation so I guess is not implemented yet.

    https://developer.apple.com/documentation/apptrackingtransparency

    We will have ios14 out this month probably, so it will be nice to be able to show the request tracking dialog and have our games ready.
     
  2. aero80

    aero80

    Joined:
    Jan 29, 2013
    Posts:
    27
    Have you found a way to do this?
     
  3. IvyKun

    IvyKun

    Joined:
    Sep 28, 2013
    Posts:
    132
    There are external plugins to do it in the asset store. But Apple has delayed the requirement until next year, so I guess Unity will add the native dialog sooner or later before it happens.
     
  4. KateKhinkelIridescent

    KateKhinkelIridescent

    Joined:
    Aug 21, 2020
    Posts:
    9
    You can call this dialog by yourself, but to handle the answer need to make custom plugin
    • follow the Guide
    • add App Tracking Transparency framework (make it optional to support older iOS versions Thread)
     
    IvyKun likes this.
  5. IvyKun

    IvyKun

    Joined:
    Sep 28, 2013
    Posts:
    132
    KateKhinkelIridescent and Endahs like this.
  6. Endahs

    Endahs

    Joined:
    Sep 16, 2014
    Posts:
    94
    We also need this soon. It's strange that we have to rely on 3rd party plugins to get this done and it's not available through Unity (without preview).

    I also hope it's going to be available through Unity -without- having to implement Unity Ads.
     
    IvyKun likes this.
  7. IvyKun

    IvyKun

    Joined:
    Sep 28, 2013
    Posts:
    132
    KateKhinkelIridescent likes this.
  8. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    515
    The thing is that it just doesn't work :D
    2020.1.17 - calling the authorization request does nothing
     
  9. IvyKun

    IvyKun

    Joined:
    Sep 28, 2013
    Posts:
    132
    I tested with 2019.4.17 I think and was working fine.

    - Import the ios support package from the package manager
    - Create a script that shows the IDFA popup and put it in an object in the main scene
    ATTrackingStatusBinding.RequestAuthorizationTracking();
    - Create the postbuild script or add manually the "NSUserTrackingUsageDescription" to the Info.plist.

    Run it in a device with ios14 (needs to be ios14) and it shows the IDFA popup just fine.

    Maybe you miss something in the steps?

    Also check on your device:
    Settings -> Privacy -> Tracking
    Settings -> Privacy -> Apple Advertising
     
    Protozoaire and novaVision like this.
  10. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    515
    You are right, Tracking framework wasn't attached to Unity project in Xcode. So I could call the request dialog
    Btw, by some reason this method
    Code (CSharp):
    1. ATTrackingStatusBinding.GetAuthorizationTrackingStatus()
    works only once... weird
     
    Last edited: Mar 16, 2021
  11. IvyKun

    IvyKun

    Joined:
    Sep 28, 2013
    Posts:
    132
    Yeah that's the way it's supposed to work, Apple only allows to show the users the tracking popup once. But if you uninstall and install your app again, it will show again.
     
  12. ByteBrew

    ByteBrew

    Joined:
    Mar 24, 2021
    Posts:
    2
    If you guys need a way to request the app tracking transparency pop-up without having to create a custom script to handle the wait function to pass a change in updated consent status to all your external SDK's that rely on user consent, take a look at our new Unity SDK, ByteSyze.

    ByteSyze handles ATT using our custom app tracking transparency completion handler for free, so you don't need create custom scripts or work with native code. Here is our Github and Docs for the SDK.

    We know getting the most updated status is important because other SDK's that rely on the user completion of ATT need to be informed of user consent or they won't get the right initialized settings.
     
  13. lupidan

    lupidan

    Joined:
    Jan 14, 2014
    Posts:
    47
    CAREFUL!!!

    Some of this preview package functionality is broken. In particular...
    https://github.com/Unity-Technologi.../Runtime/Plugins/iOS/SkAdNetworkManager.m#L38

    There is a typo in the selector name, so that will never be called.
    Plus... the way they are detecting whether any of the frameworks are available or not is QUITE questionable (runtime checks for frameworks?! WHAT?!)

    I wonder if Unity accepts PRs to fix all those issues.
     
    IvyKun likes this.
  14. smithmj5

    smithmj5

    Joined:
    May 24, 2013
    Posts:
    143
    My understanding about the runtime framework check is that it's to avoid crashes on older versions of iOS. I tried including AppTrackingTransparency.framework in my game using AddFrameworkToProject, and it results in a hard crash on any version of iOS < 14.

    Is there another way to handle it, other than a runtime check?

    And I completely agree that it would be great if Unity would fix the issues in this package, and mark it as verified, especially considering the Apple privacy changes are likely to happen any day now...
     
  15. lupidan

    lupidan

    Joined:
    Jan 14, 2014
    Posts:
    47
    @smithmj5 Yes!

    You have compiler checks and availability checks.
    - Compiler checks do look up the minimum and the maximum used SDK for compiling.
    - Availability checks perform runtime checks depending on the iOS version, and are officially supported by the Xcode compiler, giving you a warning if you are trying to use an API outside an availability check.

    You don't need to check if a framework is loaded up or perform selectors by name at all!! The code would just look something like this:

    Code (csharp):
    1.  
    2. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000 // Compiler check for SDK being used
    3. #import <AppTrackingTransparency/AppTrackingTransparency.h>
    4. #endif
    5.  
    6. (...)
    7.  
    8. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000 // Compiler check for SDK being used
    9.     if (@available(iOS 14.0, *)) { // Runtime availability check
    10.         [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
    11.             // HANDLE CALLBACK
    12.         }];
    13.     } else {
    14.         // FALLBACK CODE IN UNSUPPORTED IOS VERSIONS
    15.     }
    16. #else
    17.     // FALLBACK CODE IN UNSUPPORTED COMPILER SDK
    18. #endif
    19.  
    Finally, on a Post Processing script, you add the "AppTrackingTransparency.framework" as Optional, and done.

    I'm now working on a quick plugin to add support for this app tracking transparency request, with editor and post-processing support.
     
  16. smithmj5

    smithmj5

    Joined:
    May 24, 2013
    Posts:
    143
    Apple has announced a release date of the week of April 26, 2021 for iOS 14.5.

    Are there any plans by Unity to update this plugin and promote it to a release-ready package (instead of a preview package)?
     
  17. IvyKun

    IvyKun

    Joined:
    Sep 28, 2013
    Posts:
    132
    Version 1.0 is live since a couple of days ago with fixes and improvements, yay!
     
    pahe likes this.
  18. meuklight

    meuklight

    Joined:
    Feb 2, 2016
    Posts:
    12
    @IvyKun Do I need to handle callback? I mean after the user denied tracking do I have to manually disable analytics or iOS itself will disable tracking.
     
  19. IvyKun

    IvyKun

    Joined:
    Sep 28, 2013
    Posts:
    132
    @meuklight You don't need to do anything, if the user don't enable tracking when anything calls for the IDFA iOS will return 00000000-0000-0000-0000-000000000000 instead of the real IDFA.
     
    Last edited: Jun 1, 2021
    AndreaMar likes this.
  20. RSH1

    RSH1

    Joined:
    Jul 9, 2012
    Posts:
    255
    My code is

    Code (CSharp):
    1. void Awake()
    2.     {
    3. #if UNITY_IOS
    4.         // Check the user's consent status.
    5.         // If the status is undetermined, display the request request:
    6.         if (ATTrackingStatusBinding.GetAuthorizationTrackingStatus() == ATTrackingStatusBinding.AuthorizationTrackingStatus.NOT_DETERMINED)
    7.         {
    8.             ATTrackingStatusBinding.RequestAuthorizationTracking();
    9.         }
    10. #endif
    11.     }
    But it's not showing the request dialog when deploying on iOs. What's wrong?
     
  21. Lumpazy

    Lumpazy

    Joined:
    Apr 24, 2018
    Posts:
    43
    I wonder :
    can someone explain how to attach a nice callback to the AATRequest, so that on the first run the
    UnityEngine.Advertisements can be initialized and used right after the user made the choice ?

    I thought there must be a callback, but i can't find any in the docs. Must be missing something here. ;/
     
  22. lupidan

    lupidan

    Joined:
    Jan 14, 2014
    Posts:
    47
    I have been implementing some package of my own to handle this AppTrackingTransparency stuff. I even added some editor tools to simulate what you would get in an actual iOS device.

    You can check it here:
    https://github.com/lupidan/unity-apptrackingtransparency

    It is still WIP, but in case someone wants to take a look, there it is.
     
    ajon542 likes this.
  23. smithmj5

    smithmj5

    Joined:
    May 24, 2013
    Posts:
    143
    There is no callback.

    The call to

    Code (CSharp):
    1. Unity.Advertisement.IosSupport.ATTrackingStatusBinding.RequestAuthorizationTracking
    shows a native iOS dialog that should pause execution of your code, so after making that call you can initialize whatever you want based on the value that the user selected (it will have been set by that point, when the native dialog has been dismissed).
     
  24. Dawdlebird

    Dawdlebird

    Joined:
    Apr 22, 2013
    Posts:
    88
    Does anyone know what happens if this runs on ios 13 or lower? The lack of callback has forced me to put a coroutine in place to wait for ATTrackingStatusBinding.GetAuthorizationTrackingStatus() to no longer be ATTrackingStatusBinding.AuthorizationTrackingStatus.NOT_DETERMINED, but I suspect that lower ios versions will get stuck on 'not determined' (since the request popup doesn't actually show)...
     
    aurelienpic and novaVision like this.
  25. smithmj5

    smithmj5

    Joined:
    May 24, 2013
    Posts:
    143
    On the older preview version of the package, attempting to call that on iOS < 14 would cause a crash. Not sure if that's still the case on the non-preview package.

    I'm checking if iOS 14 or higher before calling GetAuthorizationTrackingStatus (using UnityEngine.iOS.Device.systemVersion).
     
    ryokomy likes this.
  26. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    515
    Good question. I would like to know also.
     
  27. lupidan

    lupidan

    Joined:
    Jan 14, 2014
    Posts:
    47
    I believe...
    Starting from iOS 14.0, the API to get the permission status, and request the permission was introduced
    Starting from iOS 14.5, the IDFA will be all 0s unless the permission is requested properly

    By looking at the code:
    - The code seems to think that the permission is Not Determined if the API is not available, which is not the case. If the API is not available, then the permission is granted by default (previous iOS versions).
    - It gets classes and methods using string selectors, which should not crash the app, but it is a bit hacky. Don't expect any callback if the iOS version is lower than 14.0, since the starting call never happens.
    - I'm not sure how the `AppTrackingTransparency.framework` is added to the Xcode project, but if you want to make sure it does not crash previous iOS versions, make sure it's added as `Optional`. If it's marked as required, it could crash on app load in previous iOS versions, since they do not have the framework available.
    - Finally make sure you have the NSUserTrackingUsageDescription on the Info.plist to provide a reason for requesting the IDFA to the user, otherwise it will crash when requesting the permission
     
    Last edited: Jul 23, 2021
  28. fschaar

    fschaar

    Joined:
    Jul 3, 2012
    Posts:
    14
    I have the same Problem. Can't find out, what i could probably do wrong there. Its not showing up.
     
  29. RSH1

    RSH1

    Joined:
    Jul 9, 2012
    Posts:
    255
    I had to manually add the tracking field to the Info.plist file in XCode
     
    Protozoaire likes this.
  30. RMGK

    RMGK

    Joined:
    Sep 30, 2011
    Posts:
    75
    For me it was all in my setting on my iPhone. On iOS 15, I have to go to settings -> privacy -> tracking -> Allow Apps to Request to Track (Which was off by default)
     
  31. Dev_GTS

    Dev_GTS

    Joined:
    Mar 8, 2021
    Posts:
    5
    For me it was all in my setting on my iPhone. On iOS 15, I have to go to settings -> privacy -> tracking -> Allow Apps to Request to Track (Which was off by default), i tried to turn this on but there was some age issue with my login email , so i logged out and than tried again settings -> privacy -> tracking -> Allow Apps, working fine now.
     
  32. AndreaMar

    AndreaMar

    Joined:
    Oct 29, 2019
    Posts:
    35
    Hello all. I'm late to the party...

    I'm not using UnityAds but IronSource in my project. Can I use the iOS Advertising support package nonetheless?
     
  33. wagenheimer

    wagenheimer

    Joined:
    Jun 1, 2018
    Posts:
    322
    Were you able to fix it? It was working before, but now it does not work anymore and does not show any error message.
     
  34. leshem_unity

    leshem_unity

    Joined:
    Oct 14, 2021
    Posts:
    13
    This isn't unity ads related, you need this for iOS 14+ if you want to show any ads with any plugin.
     
  35. francesco-included

    francesco-included

    Joined:
    Oct 29, 2021
    Posts:
    11
    Unfortunately, this didn't work for me. Calling
    Code (CSharp):
    1. ATTrackingStatusBinding.GetAuthorizationTrackingStatus()
    after
    Code (CSharp):
    1. ATTrackingStatusBinding.RequestAuthorizationTracking()
    gave me a
    ATTrackingStatusBinding.AuthorizationTrackingStatus.NOT_DETERMINED
    , even if the user authorized the app.

    However, the latest version (1.2.0) of the iOS 14 Advertising Support package defines an API that includes a callback, with an
    int
    that describes the latest authorization status.

    Code (CSharp):
    1. public static void RequestAuthorizationTracking(RequestAuthorizationTrackingCompleteHandler callback)

    Code (CSharp):
    1. public delegate void RequestAuthorizationTrackingCompleteHandler(int status);