Unity packs xCode's privacy protocol to request a unique advertising identifier


There is currently no interface for directly calling Ios in Unity. You need to write it yourself and associate it with the App Tracking Transparency framework . Let me talk about the problem here when calling it through c# code. For method 1, it will only be called for the first time when you start the game. If you frequently If you call the request, the review will not be given to you, so it is usually called once. When permission is required, a prompt is usually popped up to let the user open it by himself.

Method 1 Sometimes use UnityEngine.iOS.Device.advertisingTrackingEnabled under unity to judge whether it is allowed, sometimes the request fails, it is very confusing, and no specific problem is found.
Some ios device information is required. It is recommended to call the tracking protocol later. Otherwise, the audit will not pass it to you.
Here is the UnityEngine.iOS.Device function of unity. You can check it yourself.
The advertising identifier of ios can be used as the unique identifier of ios devices.

method 1

  1. After the xcode is packaged normally, the steps are as follows, select UnityAppController.mm under Classes and add two references
    #import <AdSupport/AdSupport.h>
    #import <AppTrackingTransparency/AppTrackingTransparency.h>

insert image description here

  1. Then search for bool _unityAppReady =
    false (this field is usually packaged), if not, you need to add it yourself

insert image description here

  1. Continue to find - (void)applicationDidBecomeActive:(UIApplication*)application method, add at the end of this method
 if (@available(iOS 14, *)) {
        [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
                    }];
        } else {
            [[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled];
    }

The code part is done.
insert image description here

  1. Next, you need to go to the info to add the description of the request. You can use the field Privacy - Tracking Usage Description to add the usage description here. It can also be NSUserTrackingUsageDescription. Generally, you explain in China that "your data will be used to provide you with a better personality. optimize the ad experience.” That’s it.
    insert image description here
    Just pack it and run it. If you are afraid of filling in the wrong information, you can try to click on your info file. If it cannot be opened normally, there may be a hidden space at the end after you copy it. Just delete it. Here you need to pay attention. If you have
    insert image description here
    already After packaging and running, please delete the program on the phone and rebuild the project

Method 2

Here is a direct reference to other people's articles, Unity calls the IOS ATT authorization pop-up window (AppTrackingTransparency)

Guess you like

Origin blog.csdn.net/qq_44971861/article/details/131984893