Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'io.qonversion.sandwich:sandwich:0.0.11'
implementation 'io.qonversion.sandwich:sandwich:0.0.14'
implementation 'com.google.code.gson:gson:2.8.6'
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ import android.app.Activity
import android.app.Application
import androidx.annotation.NonNull
import com.google.gson.Gson
import com.google.gson.JsonSyntaxException
import com.qonversion.android.sdk.*
import com.qonversion.android.sdk.dto.QLaunchResult
import com.qonversion.android.sdk.dto.QPermission
import com.qonversion.android.sdk.dto.QPermissionsCacheLifetime
import com.qonversion.android.sdk.dto.eligibility.QEligibility
import com.qonversion.android.sdk.dto.offerings.QOfferings
import com.qonversion.android.sdk.dto.products.QProduct
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
Expand Down Expand Up @@ -128,8 +120,8 @@ class QonversionFlutterSdkPlugin : MethodCallHandler, FlutterPlugin, ActivityAwa
"purchaseProduct" -> purchaseProduct(args, result)
"updatePurchase" -> updatePurchase(args, result)
"updatePurchaseWithProduct" -> updatePurchaseWithProduct(args, result)
"setProperty" -> setProperty(args, result)
"setUserProperty" -> setUserProperty(args, result)
"setDefinedUserProperty" -> setDefinedUserProperty(args, result)
"setCustomUserProperty" -> setCustomUserProperty(args, result)
"addAttributionData" -> addAttributionData(args, result)
"checkTrialIntroEligibility" -> checkTrialIntroEligibility(args, result)
"storeSdkInfo" -> storeSdkInfo(args, result)
Expand Down Expand Up @@ -221,15 +213,15 @@ class QonversionFlutterSdkPlugin : MethodCallHandler, FlutterPlugin, ActivityAwa
qonversionSandwich.products(result.toResultListener())
}

private fun setProperty(args: Map<String, Any>, result: Result) {
private fun setDefinedUserProperty(args: Map<String, Any>, result: Result) {
val rawProperty = args["property"] as? String ?: return result.noProperty()
val value = args["value"] as? String ?: return result.noPropertyValue()

qonversionSandwich.setDefinedProperty(rawProperty, value)
result.success(null)
}

private fun setUserProperty(args: Map<String, Any>, result: Result) {
private fun setCustomUserProperty(args: Map<String, Any>, result: Result) {
val property = args["property"] as? String ?: return result.noProperty()
val value = args["value"] as? String ?: return result.noPropertyValue()

Expand Down
17 changes: 14 additions & 3 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@
"${BUILT_PRODUCTS_DIR}/GoogleUtilities/GoogleUtilities.framework",
"${BUILT_PRODUCTS_DIR}/PromisesObjC/FBLPromises.framework",
"${BUILT_PRODUCTS_DIR}/Qonversion/Qonversion.framework",
"${BUILT_PRODUCTS_DIR}/QonversionSandwich/QonversionSandwich.framework",
"${BUILT_PRODUCTS_DIR}/flutter_local_notifications/flutter_local_notifications.framework",
"${BUILT_PRODUCTS_DIR}/nanopb/nanopb.framework",
"${BUILT_PRODUCTS_DIR}/qonversion_flutter/qonversion_flutter.framework",
Expand All @@ -290,6 +291,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleUtilities.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FBLPromises.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Qonversion.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/QonversionSandwich.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_local_notifications.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/nanopb.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/qonversion_flutter.framework",
Expand Down Expand Up @@ -400,7 +402,10 @@
);
INFOPLIST_FILE = Runner/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
Expand Down Expand Up @@ -537,7 +542,10 @@
);
INFOPLIST_FILE = Runner/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
Expand Down Expand Up @@ -569,7 +577,10 @@
);
INFOPLIST_FILE = Runner/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
Expand Down
46 changes: 23 additions & 23 deletions ios/Classes/AutomationsPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Maria on 18.11.2021.
//

import Qonversion
import QonversionSandwich

public class AutomationsPlugin: NSObject {
private let eventChannelShownScreens = "shown_screens"
Expand All @@ -20,6 +20,8 @@ public class AutomationsPlugin: NSObject {
private var finishedActionsStreamHandler: BaseEventStreamHandler?
private var finishedAutomationsStreamHandler: BaseEventStreamHandler?

private var automationSandwich = AutomationsSandwich()

public func register(_ registrar: FlutterPluginRegistrar) {
let shownScreensListener = FlutterListenerWrapper<BaseEventStreamHandler>(registrar, postfix: eventChannelShownScreens)
shownScreensListener.register() { self.shownScreensStreamHandler = $0 }
Expand All @@ -36,31 +38,29 @@ public class AutomationsPlugin: NSObject {
let finishedAutomationsListener = FlutterListenerWrapper<BaseEventStreamHandler>(registrar, postfix: eventChannelFinishedAutomations)
finishedAutomationsListener.register() { self.finishedAutomationsStreamHandler = $0 }

Qonversion.Automations.setDelegate(self)
automationSandwich.subscribe(self)
}
}

extension AutomationsPlugin: Qonversion.AutomationsDelegate {
public func automationsDidShowScreen(_ screenID: String) {
shownScreensStreamHandler?.eventSink?(screenID)
}

public func automationsDidStartExecuting(actionResult: Qonversion.ActionResult) {
let payload = actionResult.toMap().toJson()
startedActionsStreamHandler?.eventSink?(payload)
}

public func automationsDidFailExecuting(actionResult: Qonversion.ActionResult) {
let payload = actionResult.toMap().toJson()
failedActionsStreamHandler?.eventSink?(payload)
}

public func automationsDidFinishExecuting(actionResult: Qonversion.ActionResult) {
let payload = actionResult.toMap().toJson()
finishedActionsStreamHandler?.eventSink?(payload)
}
extension AutomationsPlugin: AutomationsEventListener {

public func automationsFinished() {
finishedAutomationsStreamHandler?.eventSink?(nil)
public func automationDidTrigger(event: String, payload: [String: Any]?) {
guard let resultEvent = AutomationsEvent(rawValue: event) else { return }

let handler: BaseEventStreamHandler?
switch (resultEvent) {
case .screenShown:
handler = shownScreensStreamHandler
case .actionStarted:
handler = startedActionsStreamHandler
case .actionFailed:
handler = failedActionsStreamHandler
case .actionFinished:
handler = finishedActionsStreamHandler
case .automationsFinished:
handler = finishedAutomationsStreamHandler
}

handler?.eventSink?(payload?.toJson())
}
}
17 changes: 0 additions & 17 deletions ios/Classes/Constants.swift

This file was deleted.

19 changes: 19 additions & 0 deletions ios/Classes/Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Extensions.swift
// qonversion_flutter
//
// Created by Kamo Spertsyan on 05.09.2022.
//

import Foundation

extension Dictionary {
func toJson() -> String? {
guard let jsonData = try? JSONSerialization.data(withJSONObject: self,
options: []) else {
return nil
}

return String(data: jsonData, encoding: .utf8)
}
}
63 changes: 21 additions & 42 deletions ios/Classes/FlutterError+Custom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import FlutterMacOS
import Flutter
#endif

import QonversionSandwich

extension FlutterError {
static private let passValidValue = "Please make sure you pass a valid value"

Expand All @@ -26,10 +28,6 @@ extension FlutterError {
message: "Could not find userID",
details: passValidValue)

static let noAutoTrackPurchases = FlutterError(code: "3",
message: "Could not find autoTrackPurchases boolean value",
details: passValidValue)

static let noData = FlutterError(code: "4",
message: "Could not find data",
details: passValidValue)
Expand All @@ -38,26 +36,22 @@ extension FlutterError {
message: "Could not find provider",
details: passValidValue)

static func failedToGetProducts(_ error: NSError) -> FlutterError {
return mapQonversionError(error, errorCode: "7", errorMessage: "Failed to get products")
static func failedToGetProducts(_ error: SandwichError) -> FlutterError {
return mapSandwichError(error, errorCode: "7", errorMessage: "Failed to get products")
}

static let noProductId = FlutterError(code: "8",
message: "Could not find productId value",
details: "Please provide valid productId")

static let noProduct = FlutterError(code: "ProductNotProvided",
message: "Could not find product",
details: "Please provide a valid product")

static func qonversionError(_ error: NSError) -> FlutterError {
return mapQonversionError(error, errorCode: "9")

static func sandwichError(_ error: SandwichError) -> FlutterError {
return mapSandwichError(error, errorCode: "9")
}

static func parsingError(_ description: String) -> FlutterError {
return FlutterError(code: "12",
message: "Arguments Parsing Error",
details: description)
static func purchaseError(_ error: SandwichError) -> FlutterError {
let isCancelled = error.additionalInfo["isCancelled"] as? Bool ?? false
let code = isCancelled ? "PurchaseCancelledByUser" : "9"
return mapSandwichError(error, errorCode: code)
}

static let noProperty = FlutterError(code: "13",
Expand All @@ -67,49 +61,34 @@ extension FlutterError {
static let noPropertyValue = FlutterError(code: "14",
message: "Could not find property value",
details: passValidValue)

static func offeringsError(_ error: NSError) -> FlutterError {
return mapQonversionError(error, errorCode: "Offerings", errorMessage: "Could not get offerings")
}


static let noSdkInfo = FlutterError(code: "15",
message: "Could not find sdk info",
details: passValidValue)

static let noLifetime = FlutterError(code: "16",
message: "Could not find lifetime",
details: passValidValue)

static func promoPurchaseError(_ productId: String) -> FlutterError {
return FlutterError (code: "PromoPurchase",
message: "Could not find completion block for Product ID: \(productId)",
details: passValidValue)
}

static func jsonSerializationError(_ description: String) -> FlutterError {
return FlutterError(code: "JSONSerialization",
message: "JSON Serialization Error",
details: description)

}
static let noOfferingId = FlutterError(code: "17",
message: "Could not find offeringId value",
details: "Please provide valid offeringId")

static func noProductIdField(_ description: String) -> FlutterError {
return FlutterError(code: "NoProductIdField",
message: "Could not find qonversionId in Product",
details: description)
}
static let serializationError = FlutterError(code: "18",
message: "Failed to serialize response from native bridge",
details: "")

private static func mapQonversionError(_ error: NSError, errorCode: String, errorMessage: String? = nil) -> FlutterError {
private static func mapSandwichError(_ error: SandwichError, errorCode: String, errorMessage: String? = nil) -> FlutterError {
var message = ""

if let errorMessage = errorMessage {
message = errorMessage + ". "
}
message += error.localizedDescription
message += error.details

var details = "Qonversion Error Code: \(error.code)"

if let additionalMessage = error.userInfo[NSDebugDescriptionErrorKey] {
if let additionalMessage = error.additionalMessage {
details = "\(details). Additional Message: \(additionalMessage)"
}

Expand Down
Loading