I am updating my Uno based app and in testing-the app tracking prompt no longer appears. I had implemented this and it works correctly in iOS 14. In iOS 14 I am able to go into the privacy settings and see that the user has selected if they want to be tracked or not. I dont see any of this in iOS 15. In my research, it appears that I need to override the onActivated method in appDelegate and put the prompt code in there. I dont have an appDelegate class in my project so I tried adding one in app.iOS but it could not find the formsApplicationdelegate the example had. Also- when I look in settings in iOS it does not show the app as having a tracking/no tracking choice. I am guessing this will show once I get the prompt to show? I did verify the setting is in my info.plist. What is the best way to do this?
Here is my current implementation:
info.plist:
<key>NSUserTrackingUsageDescription</key>
<string>The App would like to access the identifier for analytics purposes</string>
MainPage.xaml.cs:
#if __IOS__
using AppTrackingTransparency;
#endif
public sealed partial class MainPage : Page
{
public MainPage()
{
#if __IOS__
try
{
ATTrackingManager.RequestTrackingAuthorization((status) => {
if (status == ATTrackingManagerAuthorizationStatus.Authorized)
{
//do something
}
else if (status == ATTrackingManagerAuthorizationStatus.Denied)
{
//do something
}
});
}
catch (Exception e)
{
//do something
}
#endif
}
}
CodePudding user response:
In my research, it appears that I need to override the onActivated method in appDelegate and put the prompt code in there. I dont have an appDelegate class in my project (...)
The App class (in App.xaml.cs) inherits from Windows.UI.Xaml.Application which in turn inherits from UIApplicationDelegate.
This means you should be able to do the following in App.xaml.cs.
#if __IOS__
public override void OnActivated(UIKit.UIApplication application)
{
// Some of your code.
base.OnActivated(application);
// Some of your code.
}
#endif
