Last active
February 19, 2021 15:45
-
-
Save Jasper7/f5ea52e4db649e6342705557dbe57bb2 to your computer and use it in GitHub Desktop.
[Xamarin][iOS] Request AppTracking transparency permission for iOS 14+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Dont forgot register service | |
//[assembly: Xamarin.Forms.Dependency(typeof(YourNameSpace.iOS.Services.AdTrackingService))] | |
public class AdTrackingService : ITrackingService | |
{ | |
public void RequestAppTracking() | |
{ | |
ATTrackingManager.RequestTrackingAuthorization(OnCompleteRequest); | |
} | |
private void OnCompleteRequest(ATTrackingManagerAuthorizationStatus obj) | |
{ | |
switch (obj) | |
{ | |
case ATTrackingManagerAuthorizationStatus.Authorized: | |
//Any action | |
break; | |
case ATTrackingManagerAuthorizationStatus.Restricted: | |
//Any action | |
break; | |
case ATTrackingManagerAuthorizationStatus.NotDetermined: | |
//Any action | |
break; | |
case ATTrackingManagerAuthorizationStatus.Denied: | |
//Any action | |
break; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>NSUserTrackingUsageDescription</key> | |
<string>This identifier will be used to deliver personalized ads to you</string> | |
<!-- Other SKAD networks Ids find here: https://developers.ironsrc.com/ironsource-mobile/ios/ios-14-network-support --> | |
<key>SKAdNetworkItems</key> | |
<array> | |
<dict> | |
<key>AdMob</key> | |
<string>su67r6k2v3.skadnetwork</string> | |
<key>Facebook</key> | |
<string>v9wttpbfk9.skadnetwork</string> | |
<key>Facebook2</key> | |
<string>n38lu8286q.skadnetwork</string> | |
</dict> | |
</array> | |
</dict> | |
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ITrackingService | |
{ | |
void RequestAppTracking(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in your code: | |
var trackingService = DependencyService.Get<ITrackingService>(); | |
trackingService.RequestAppTracking(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment