Skip to content

Commit

Permalink
Merge pull request #115 from qonversion/release/3.7.0
Browse files Browse the repository at this point in the history
Release 3.7.0
  • Loading branch information
SpertsyanKM authored Sep 29, 2022
2 parents c769052 + 0e5cc9e commit b0c67be
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 9 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.sandwich:sandwich:0.1.2" />
<androidPackage spec="io.qonversion.sandwich:sandwich:0.2.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="QonversionSandwich" version="0.1.2" />
<iosPod name="QonversionSandwich" version="0.2.0" />
</iosPods>
</dependencies>
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.qonversion.sandwich.SandwichError;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class QonversionWrapper {
public static String TAG = "QonversionWrapper";
Expand Down Expand Up @@ -159,6 +160,24 @@ public static synchronized boolean handleNotification(String notification) {
}
}

@Nullable
public static synchronized Map<String, Object> getNotificationCustomPayload(String notification) {
try {
ObjectMapper mapper = new ObjectMapper();

TypeReference<HashMap<String, String>> typeRef
= new TypeReference<HashMap<String, String>>() {
};
Map<String, String> notificationInfo = mapper.readValue(notification, typeRef);

Map<String, Object> payload = qonversionSandwich.getNotificationCustomPayload(notificationInfo);

return payload;
} catch (Exception e) {
return null;
}
}

public static synchronized void subscribeOnAutomationEvents() {
automationsWrapper.subscribe();
}
Expand Down
7 changes: 7 additions & 0 deletions Runtime/Android/QonversionWrapperAndroid.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using QonversionUnity.MiniJSON;
using UnityEngine;

namespace QonversionUnity
Expand Down Expand Up @@ -154,6 +156,11 @@ public bool HandleNotification(string notification)
return CallQonversion<bool>("handleNotification", notification);
}

public string GetNotificationCustomPayload(string notification)
{
return CallQonversion<string>("getNotificationCustomPayload", notification);
}

public void SubscribeOnAutomationEvents()
{
CallQonversion("subscribeOnAutomationEvents");
Expand Down
5 changes: 4 additions & 1 deletion Runtime/Scripts/IQonversionWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace QonversionUnity
using JetBrains.Annotations;

namespace QonversionUnity
{
internal interface IQonversionWrapper
{
Expand Down Expand Up @@ -26,6 +28,7 @@ internal interface IQonversionWrapper
void PromoPurchase(string storeProductId, string callbackName);
void SetNotificationsToken(string token);
bool HandleNotification(string notification);
[CanBeNull] string GetNotificationCustomPayload(string notification);
void SubscribeOnAutomationEvents();
void PresentCodeRedemptionSheet();
void SetPermissionsCacheLifetime(string lifetime);
Expand Down
20 changes: 20 additions & 0 deletions Runtime/Scripts/Models/Permission.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public class Permission
/// A renew state for an associate product that unlocked permission
public readonly QProductRenewState RenewState;

/// A source determining where this permission is originally from - App Store, Play Store, Stripe, etc.
public readonly QPermissionSource Source;

/// Purchase date
public readonly DateTime StartedDate;

Expand All @@ -33,6 +36,7 @@ public Permission(Dictionary<string, object> dict)
if (dict.TryGetValue("id", out object value)) PermissionID = value as string;
if (dict.TryGetValue("associatedProduct", out value)) ProductID = value as string;
if (dict.TryGetValue("renewState", out value)) RenewState = FormatRenewState(value);
Source = dict.TryGetValue("source", out value) ? FormatPermissionSource(value) : QPermissionSource.Unknown;
if (dict.TryGetValue("active", out value)) IsActive = (bool)value;
if (dict.TryGetValue("startedTimestamp", out value)) StartedDate = FormatDate(value);
if (dict.TryGetValue("expirationTimestamp", out value) && value != null) ExpirationDate = FormatDate(value);
Expand All @@ -43,6 +47,7 @@ public override string ToString()
return $"{nameof(PermissionID)}: {PermissionID}, " +
$"{nameof(ProductID)}: {ProductID}, " +
$"{nameof(RenewState)}: {RenewState}, " +
$"{nameof(Source)}: {Source}, " +
$"{nameof(StartedDate)}: {StartedDate}, " +
$"{nameof(ExpirationDate)}: {ExpirationDate}, " +
$"{nameof(IsActive)}: {IsActive}";
Expand All @@ -58,6 +63,12 @@ private DateTime FormatDate(object time) {

private QProductRenewState FormatRenewState(object renewState) =>
(QProductRenewState)Convert.ToInt32(renewState);

private QPermissionSource FormatPermissionSource(object source) {
return Enum.TryParse(source.ToString(), out QPermissionSource parsedSource)
? parsedSource
: QPermissionSource.Unknown;
}
}

public enum QProductRenewState
Expand All @@ -75,4 +86,13 @@ public enum QProductRenewState
/// Prompt the user to update the payment method.
BillingIssue = 3
}

public enum QPermissionSource
{
Unknown,
AppStore,
PlayStore,
Stripe,
Manual
}
}
22 changes: 21 additions & 1 deletion Runtime/Scripts/Qonversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class Qonversion : MonoBehaviour
private const string OnOfferingsMethodName = "OnOfferings";
private const string OnEligibilitiesMethodName = "OnEligibilities";

private const string SdkVersion = "3.6.2";
private const string SdkVersion = "3.7.0";
private const string SdkSource = "unity";

private static IQonversionWrapper _Instance;
Expand Down Expand Up @@ -531,6 +531,26 @@ public static bool HandleNotification(Dictionary<string, object> notification)
return instance.HandleNotification(notification.toJson());
}

[CanBeNull]
public static Dictionary<string, object> GetNotificationCustomPayload(Dictionary<string, object> notification)
{
IQonversionWrapper instance = getFinalInstance();
var payloadJson = instance.GetNotificationCustomPayload(notification.toJson());

if (payloadJson == null)
{
return null;
}

if (!(Json.Deserialize(payloadJson) is Dictionary<string, object> response))
{
Debug.LogError("Could not parse custom notification payload.");
return null;
}

return response;
}

// Called from the native SDK - Called when launch completed
private void OnLaunch(string jsonString)
{
Expand Down
5 changes: 5 additions & 0 deletions Runtime/Scripts/QonversionWrapperNoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ public bool HandleNotification(string notification)
return false;
}

public string GetNotificationCustomPayload(string notification)
{
return null;
}

public void SubscribeOnAutomationEvents()
{
}
Expand Down
1 change: 1 addition & 0 deletions Runtime/iOS/Plugins/Common/UtilityBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
+ (NSDictionary*)dictionaryFromJsonString:(NSString*) jsonString;
+ (NSDictionary *)convertError:(SandwichError *)error;
+ (NSDictionary *)convertSandwichError:(SandwichError *)error;
+ (const char *)jsonStringFromObject:(NSObject *)objectToConvert;

+ (void)sendUnityMessage:(NSObject *)objectToConvert toMethod:(NSString *)methodName
unityListener:(const char *)unityListenerName;
Expand Down
19 changes: 15 additions & 4 deletions Runtime/iOS/Plugins/Common/UtilityBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,30 @@ + (void)handleErrorResponse:(SandwichError *)error toMethod:(NSString *)methodNa
[UtilityBridge sendUnityMessage:errorDict toMethod:methodName unityListener: unityListenerName];
}

+ (void)sendUnityMessage:(NSObject *)objectToConvert toMethod:(NSString *)methodName
unityListener:(const char *)unityListenerName{
+ (const char *)jsonStringFromObject:(NSObject *)objectToConvert{
NSError *error = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:objectToConvert options:0 error:&error];

if (error) {
NSLog(@"An error occurred while serializing data: %@", error.localizedDescription);
return;
return nil;
}

if (jsonData) {
NSString *json = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
UnitySendMessage(unityListenerName, methodName.UTF8String, json.UTF8String);
return json.UTF8String;
}
return nil;
}

+ (void)sendUnityMessage:(NSObject *)objectToConvert toMethod:(NSString *)methodName
unityListener:(const char *)unityListenerName{
const char *data = [UtilityBridge jsonStringFromObject:objectToConvert];

if (data) {
UnitySendMessage(unityListenerName, methodName.UTF8String, data);
}
return;
}

+ (void)handleResult:(NSDictionary *)result
Expand Down
14 changes: 14 additions & 0 deletions Runtime/iOS/Plugins/QonversionBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,20 @@ bool _handleNotification(const char* notification) {
return isQonversionNotification;
}

const char* _getNotificationCustomPayload(const char* notification) {
NSDictionary *notificationInfo = [UtilityBridge dictionaryFromJsonString: [UtilityBridge сonvertCStringToNSString: notification]];

NSDictionary *payload = [qonversionSandwich getNotificationCustomPayload:notificationInfo];

if (payload == nil) {
return nil;
}

const char *data = [UtilityBridge jsonStringFromObject:payload];

return data;
}

void _subscribeOnAutomationEvents() {
[automationsDelegate subscribe];
}
12 changes: 12 additions & 0 deletions Runtime/iOS/QonversionWrapperIOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ internal class QonversionWrapperIOS : IQonversionWrapper
[DllImport("__Internal")]
private static extern bool _handleNotification(string notification);

[DllImport("__Internal")]
private static extern string _getNotificationCustomPayload(string notification);

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

Expand Down Expand Up @@ -254,6 +257,15 @@ public bool HandleNotification(string notification)
#endif
}

public string GetNotificationCustomPayload(string notification)
{
#if UNITY_IOS
return _getNotificationCustomPayload(notification);
#else
return null;
#endif
}

public void SubscribeOnAutomationEvents()
{
#if UNITY_IOS
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.qonversion.unity",
"displayName": "Qonversion",
"version": "3.6.2",
"version": "3.7.0",
"unity": "2018.3",
"description": "Empower your mobile app marketing and product decisions with precise subscription data.",
"author": {
Expand Down

0 comments on commit b0c67be

Please sign in to comment.