Skip to content

Commit

Permalink
Fault tolerance and Firebase instance id support. (#89)
Browse files Browse the repository at this point in the history
* Fault tolerance and Firebase instance id support.

* Comment fix

* CR fixes
  • Loading branch information
SpertsyanKM authored Aug 26, 2022
1 parent 34175b4 commit 6e3bcce
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Editor/QonversionDependencies.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<dependencies>
<androidPackages>
<androidPackage spec="io.qonversion.android.sdk:sdk:3.2.4" />
<androidPackage spec="io.qonversion.android.sdk:sdk:3.3.0" />
<androidPackage spec="com.fasterxml.jackson.core:jackson-databind:2.11.1" />
<androidPackage spec="org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.61" />
</androidPackages>
<iosPods>
<iosPod name="Qonversion" version="2.18.3" />
<iosPod name="Qonversion" version="2.20.0" />
</iosPods>
</dependencies>
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.qonversion.android.sdk.QonversionPermissionsCallback;
import com.qonversion.android.sdk.dto.QLaunchResult;
import com.qonversion.android.sdk.dto.QPermission;
import com.qonversion.android.sdk.dto.QPermissionsCacheLifetime;

import android.preference.PreferenceManager;

Expand Down Expand Up @@ -289,6 +290,15 @@ public static synchronized void removeUpdatedPurchasesDelegate() {
updatedPurchasesListener = null;
}

public static synchronized void setPermissionsCacheLifetime(String lifetimeKey) {
try {
QPermissionsCacheLifetime lifetime = QPermissionsCacheLifetime.valueOf(lifetimeKey);
Qonversion.setPermissionsCacheLifetime(lifetime);
} catch (IllegalArgumentException e) {
Log.e(TAG, "Failed to map QPermissionsCacheLifetime. " + e.getLocalizedMessage());
}
}

public static synchronized void setNotificationsToken(String token) {
Qonversion.setNotificationsToken(token);
}
Expand Down
6 changes: 6 additions & 0 deletions Runtime/Android/QonversionWrapperAndroid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,11 @@ public void AddPromoPurchasesDelegate()
public void RemovePromoPurchasesDelegate()
{
}

public void SetPermissionsCacheLifetime(PermissionsCacheLifetime lifetime)
{
string lifetimeName = Enum.GetName(typeof(PermissionsCacheLifetime), lifetime);
CallQonversion("setPermissionsCacheLifetime", lifetimeName);
}
}
}
1 change: 1 addition & 0 deletions Runtime/Scripts/IQonversionWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ internal interface IQonversionWrapper
bool HandleNotification(string notification);
void AddAutomationsDelegate();
void PresentCodeRedemptionSheet();
void SetPermissionsCacheLifetime(PermissionsCacheLifetime lifetime);
}
}
14 changes: 14 additions & 0 deletions Runtime/Scripts/Models/PermissionsCacheLifetime.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace QonversionUnity
{
public enum PermissionsCacheLifetime
{
WEEK,
TWO_WEEKS,
MONTH,
TWO_MONTHS,
THREE_MONTHS,
SIX_MONTHS,
YEAR,
UNLIMITED
}
}
11 changes: 11 additions & 0 deletions Runtime/Scripts/Models/PermissionsCacheLifetime.cs.meta

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

3 changes: 2 additions & 1 deletion Runtime/Scripts/Models/UserProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public enum UserProperty
AdjustAdId,
KochavaDeviceId,
CustomUserId,
FacebookAttribution
FacebookAttribution,
FirebaseAppInstanceId
}
}
13 changes: 13 additions & 0 deletions Runtime/Scripts/Qonversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,19 @@ public static void CheckTrialIntroEligibilityForProductIds(IList<string> product
IQonversionWrapper instance = getFinalInstance();
instance.CheckTrialIntroEligibilityForProductIds(productIdsJson, OnEligibilitiesMethodName);
}

/// <summary>
/// Permissions cache is used when there are problems with the Qonversion API
/// or internet connection. If so, Qonversion will return the last successfully loaded
/// permissions. The current method allows you to configure how long that cache may be used.
/// The default value is <see cref="PermissionsCacheLifetime.MONTH>.
/// </summary>
/// <param name="lifetime">Desired permissions cache lifetime duration.</param>
public static void SetPermissionsCacheLifetime(PermissionsCacheLifetime lifetime)
{
IQonversionWrapper instance = getFinalInstance();
instance.SetPermissionsCacheLifetime(lifetime);
}

/// <summary>
/// Set push token to Qonversion to enable Qonversion push notifications
Expand Down
5 changes: 5 additions & 0 deletions Runtime/Scripts/QonversionWrapperNoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,10 @@ public void PresentCodeRedemptionSheet()
{

}

public void SetPermissionsCacheLifetime(PermissionsCacheLifetime lifetime)
{

}
}
}
1 change: 1 addition & 0 deletions Runtime/iOS/Plugins/Common/UtilityBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
+ (NSDictionary *)convertActionResult:(QONActionResult *)actionResult;
+ (NSDictionary *)convertError:(NSError *)error;
+ (NSDictionary *)convertAutomationsEvent:(QONAutomationsEvent *)event;
+ (NSNumber *)convertPermissionsCacheLifetime:(NSString *)lifetimeKey;

@end
17 changes: 17 additions & 0 deletions Runtime/iOS/Plugins/Common/UtilityBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ + (NSNumber *)convertProperty:(NSString *)propertyStr {
@"AdjustAdId": @(QNPropertyAdjustUserID),
@"KochavaDeviceId": @(QNPropertyKochavaDeviceID),
@"CustomUserId": @(QNPropertyUserID),
@"FirebaseAppInstanceId": @(QNPropertyFirebaseAppInstanceId),
};

NSNumber *propertyIndex = propertiesDict[propertyStr];
Expand Down Expand Up @@ -397,4 +398,20 @@ + (NSDictionary *)convertAutomationsEvent:(QONAutomationsEvent *)event {
return [result copy];
}

+ (NSNumber *)convertPermissionsCacheLifetime:(NSString *)lifetimeKey {
NSDictionary *lifetimesDict = @{
@"WEEK": @(QNPermissionsCacheLifetimeWeek),
@"TWO_WEEKS": @(QNPermissionsCacheLifetimeTwoWeeks),
@"MONTH": @(QNPermissionsCacheLifetimeMonth),
@"TWO_MONTHS": @(QNPermissionsCacheLifetimeTwoMonth),
@"THREE_MONTHS": @(QNPermissionsCacheLifetimeThreeMonth),
@"SIX_MONTHS": @(QNPermissionsCacheLifetimeSixMonth),
@"YEAR": @(QNPermissionsCacheLifetimeYear),
@"UNLIMITED": @(QNPermissionsCacheLifetimeUnlimited),
};

NSNumber *lifetimeIndex = lifetimesDict[lifetimeKey];
return lifetimeIndex;
}

@end
9 changes: 9 additions & 0 deletions Runtime/iOS/Plugins/QonversionBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,15 @@ void _removeUpdatedPurchasesDelegate() {
purchasesDelegate = nil;
}

void _setPermissionsCacheLifetime(const char* lifetimeName) {
NSString *lifetimeNameStr = [UtilityBridge сonvertCStringToNSString:lifetimeName];
NSNumber *lifetimeIndex = [UtilityBridge convertPermissionsCacheLifetime:lifetimeNameStr];

if (lifetimeIndex) {
[Qonversion setPermissionsCacheLifetime:lifetimeIndex.integerValue];
}
}

void _setNotificationsToken(const char* token) {
NSString *hexString = [UtilityBridge сonvertCStringToNSString:token];
NSData *tokenData = [UtilityBridge convertHexToData:hexString];
Expand Down
13 changes: 12 additions & 1 deletion Runtime/iOS/QonversionWrapperIOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ internal class QonversionWrapperIOS : IQonversionWrapper

[DllImport("__Internal")]
private static extern void _presentCodeRedemptionSheet();

[DllImport("__Internal")]
private static extern void _setPermissionsCacheLifetime(string lifetimeKey);
#endif

public void StoreSdkInfo(string version, string versionKey, string source, string sourceKey)
Expand Down Expand Up @@ -131,8 +134,8 @@ public void SetUserProperty(string key, string value)

public void SetProperty(UserProperty key, string value)
{
string propertyName = Enum.GetName(typeof(UserProperty), key);
#if UNITY_IOS
string propertyName = Enum.GetName(typeof(UserProperty), key);
_setProperty(propertyName, value);
#endif
}
Expand Down Expand Up @@ -284,6 +287,14 @@ public void AddAutomationsDelegate()
{
#if UNITY_IOS
_subscribeAutomationsDelegate();
#endif
}

public void SetPermissionsCacheLifetime(PermissionsCacheLifetime lifetime)
{
#if UNITY_IOS
string lifetimeName = Enum.GetName(typeof(PermissionsCacheLifetime), lifetime);
_setPermissionsCacheLifetime(lifetimeName);
#endif
}
}
Expand Down

0 comments on commit 6e3bcce

Please sign in to comment.