Skip to content

Commit

Permalink
Merge pull request #24 from SourcePointUSA/DIA-2586-clear-all-data
Browse files Browse the repository at this point in the history
[DIA-2586] Іmplementation of ClearAllData()
  • Loading branch information
Nevazhnovu authored Dec 6, 2023
2 parents 4a641ca + 66eea98 commit daefe24
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ import UIKit
ccpaPmId: ccpaPmId
)}()
}

@objc public func dispose() {
callbackDefault = nil
callbackOnConsentReady = nil
callbackOnConsentUIReady = nil
callbackOnConsentAction = nil
callbackOnConsentUIFinished = nil
callbackOnErrorCallback = nil
callbackOnSPFinished = nil
callbackOnSPUIFinished = nil
callbackOnCustomConsent = nil
}

// MARK: - Manage lib
@objc public func loadMessage(authId: String? = nil) {
Expand Down
5 changes: 5 additions & 0 deletions Assets/ConsentManagementProvider/Plugins/iOS/Source/Unity.mm
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,9 @@ void _customConsentGDPRWithVendors()
{
//TO-DO
}

void _dispose()
{
[swiftBridge dispose];
}
}
21 changes: 21 additions & 0 deletions Assets/ConsentManagementProvider/Scripts/facade/CMP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,27 @@ public static void LoadMessage(string authId = null)
#endif
}

public static void ClearAllData(string authId = null)
{
if (IsEditor)
{
Debug.LogWarning("Emulating ClearAllData call... Sourcepoint CMP works only for real Android/iOS devices, not the Unity Editor.");
return;
}

#if UNITY_ANDROID
if (Application.platform == RuntimePlatform.Android)
{
SpAndroidNativeUtils.ClearAllData();
}
#elif UNITY_IOS && !UNITY_EDITOR_OSX
if (Application.platform == RuntimePlatform.IPhonePlayer)
{
ConsentWrapperIOS.Instance.ClearAllData();
}
#endif
}

public static void LoadPrivacyManager(CAMPAIGN_TYPE campaignType, string pmId, PRIVACY_MANAGER_TAB tab)
{
if (IsEditor)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using UnityEngine;
using ConsentManagementProviderLib.Json;

namespace ConsentManagementProviderLib.Android
{
internal class SpAndroidNativeUtils
{
private static AndroidJavaClass unityPlayerClass;
private static AndroidJavaObject currentActivity;

static SpAndroidNativeUtils()
{
unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
currentActivity = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
}

public static void ClearAllData()
{
AndroidJavaClass spUtilsClass = new AndroidJavaClass("com.sourcepoint.cmplibrary.util.SpUtils");

currentActivity.Call("runOnUiThread", new AndroidJavaRunnable(() =>
{
spUtilsClass.CallStatic("clearAllData", currentActivity);
}));
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ private set
private static extern void _cleanConsent();
[DllImport("__Internal")]
private static extern void _customConsentGDPRWithVendors();
[DllImport("__Internal")]
private static extern void _dispose();
#endif

public ConsentWrapperIOS()
Expand Down Expand Up @@ -132,10 +134,17 @@ public SpConsents GetSpConsents()
return iOSListener._spConsents;
}

public void Dispose()
public void ClearAllData()
{
#if UNITY_IOS && !UNITY_EDITOR_OSX
_cleanConsent();
#endif
}

public void Dispose()
{
#if UNITY_IOS && !UNITY_EDITOR_OSX
_dispose();
#endif
}
}
Expand Down
3 changes: 1 addition & 2 deletions Assets/ExampleApp/Scripts/PrivacySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ public void OnPrivacyManagerButtonClick()

public void OnClearDataPress()
{
PlayerPrefs.DeleteAll();
CMP.ClearAllData();
storedConsentString = null;
CMP.Dispose();
updateUI();
}

Expand Down

0 comments on commit daefe24

Please sign in to comment.