This repository has been archived by the owner on Jul 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
291 additions
and
33 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#if UNITY_IOS || CASDeveloper | ||
using System.IO; | ||
using UnityEditor; | ||
using UnityEditor.Callbacks; | ||
using UnityEditor.iOS.Xcode; | ||
using UnityEngine; | ||
|
||
namespace CAS.UserConsent | ||
{ | ||
internal class PostprocessiOSBuild | ||
{ | ||
[PostProcessBuild] | ||
public static void OnPostProcessBuild( BuildTarget buildTarget, string path ) | ||
{ | ||
if (buildTarget != BuildTarget.iOS) | ||
return; | ||
var parameters = UserConsent.BuildRequest(); | ||
var trakingUsage = parameters.defaultIOSTrakingUsageDescription; | ||
if (string.IsNullOrEmpty( trakingUsage )) | ||
return; | ||
string plistPath = Path.Combine( path, "Info.plist" ); | ||
PlistDocument plist = new PlistDocument(); | ||
plist.ReadFromFile( plistPath ); | ||
plist.root.SetString( "NSUserTrackingUsageDescription", trakingUsage ); | ||
File.WriteAllText( plistPath, plist.WriteToString() ); | ||
} | ||
} | ||
} | ||
#endif |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// CASUAppTracking.m | ||
// CASUnityPlugin | ||
// | ||
// Copyright © 2021 Clever Ads Solutions. All rights reserved. | ||
// | ||
|
||
#import <AppTrackingTransparency/AppTrackingTransparency.h> | ||
|
||
typedef void (*CASUTrackingStatusCallback)(NSInteger status); | ||
|
||
void CASURequestTracking(CASUTrackingStatusCallback callback) | ||
{ | ||
if (@available(iOS 14, *)) { | ||
[ATTrackingManager | ||
requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) { | ||
if (callback) { | ||
callback((int)status); | ||
} | ||
}]; | ||
} else { | ||
if (callback) { | ||
callback(3); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace CAS.iOS | ||
{ | ||
/// <summary> | ||
/// Wraps for the native iOS 14.0 ATTrackingManager. | ||
/// A class that provides a tracking authorization request and the tracking authorization status of the app. | ||
/// <see cref="https://developer.apple.com/documentation/apptrackingtransparency/attrackingmanager"/> | ||
/// </summary> | ||
public static class AppTrackingTransparency | ||
{ | ||
public enum Status | ||
{ | ||
NotDetermined, | ||
Restricted, | ||
Denied, | ||
Authorized | ||
} | ||
|
||
/// <summary> | ||
/// Returns information about your application’s tracking authorization status. | ||
/// Users are able to grant or deny developers tracking privileges on a per-app basis. | ||
/// Application developers must call <see cref="Request()"/> for the ability to track users. | ||
/// | ||
/// The current authorization status. If the user has not yet been prompted to approve access, the return value will either be | ||
/// <see cref="Status.NotDetermined"/>, or <see cref="Status.Restricted"/> if this value is managed. | ||
/// Once the user has been prompted, the return value will be either <see cref="Status.Denied"/> or <see cref="Status.Authorized"/>. | ||
/// </summary> | ||
public static event Action<Status> OnAuthorizationRequestComplete; | ||
|
||
/// <summary> | ||
/// Request user tracking authorization with a completion handler returning the user's authorization status. | ||
/// Users are able to grant or deny developers tracking privileges on a per-app basis. | ||
/// This method allows developers to determine if access has been granted. On first use, this method will prompt the user to grant or deny access. | ||
/// | ||
/// Please set <b>NSUserTrackingUsageDescription</b> in 'Assets > CleverAdsSolutions > iOS Settings' menu to correct tracking authorization request. | ||
/// | ||
/// The completion handler will be called with the result of the user's decision for granting or denying permission to use application tracking. | ||
/// The completion handler will be called immediately if access to request authorization is restricted. | ||
/// The completion handler will be called immediately if runtime platform is not iOS 14 or newer. | ||
/// </summary> | ||
/// <exception cref="ArgumentNullException">Please subscribe callback OnAuthorizationRequestComplete before call Request()</exception> | ||
/// <exception cref="ArgumentException">Please set NSUserTrackingUsageDescription in 'Assets > CleverAdsSolutions > iOS Settings' menu to correct tracking authorization request.</exception> | ||
public static void Request() | ||
{ | ||
if (OnAuthorizationRequestComplete == null) | ||
throw new ArgumentNullException( "Please subscribe callback OnAuthorizationRequestComplete before call Request()." ); | ||
#if UNITY_IOS || CASDeveloper | ||
#if UNITY_EDITOR | ||
var settings = UserConsent.UserConsent.BuildRequest(); | ||
if (string.IsNullOrEmpty( settings.defaultIOSTrakingUsageDescription )) | ||
throw new ArgumentNullException( | ||
"Please set NSUserTrackingUsageDescription in 'Assets > CleverAdsSolutions > Consent Request parameters' menu to correct tracking authorization request." ); | ||
#endif | ||
CASURequestTracking( AuthorizationRequestComplete ); | ||
#else | ||
OnAuthorizationRequestComplete( Status.Authorized ); | ||
#endif | ||
} | ||
|
||
#if UNITY_IOS || CASDeveloper | ||
internal delegate void CASUTrackingStatusCallback( int status ); | ||
|
||
[DllImport( "__Internal" )] | ||
internal static extern void CASURequestTracking( CASUTrackingStatusCallback callback ); | ||
|
||
[AOT.MonoPInvokeCallback( typeof( CASUTrackingStatusCallback ) )] | ||
private static void AuthorizationRequestComplete( int status ) | ||
{ | ||
try | ||
{ | ||
if (OnAuthorizationRequestComplete != null) | ||
OnAuthorizationRequestComplete( ( Status )status ); | ||
} | ||
catch (Exception e) | ||
{ | ||
UnityEngine.Debug.LogException( e ); | ||
} | ||
} | ||
#endif | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.