Skip to content

Commit

Permalink
3.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
namidan committed May 15, 2023
1 parent d17545b commit 9a74455
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 182 deletions.
6 changes: 6 additions & 0 deletions sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 3.0.9 (May 15, 2023)

# Changelog

- Update bridge to support Apple SDK 3.0.9 and Android SDK 3.0.9

# 3.0.7 (Apr 20, 2023)

## Changelog
Expand Down
4 changes: 2 additions & 2 deletions sdk/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
group 'com.namiml.flutter.sdk'
version '3.0.0-alpha.03'
version '3.0.9'

buildscript {
ext.kotlin_version = '1.6.10'
ext.nami_sdk_version = '3.0.8.1'
ext.nami_sdk_version = '3.0.9'
repositories {
mavenCentral()
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import com.namiml.NamiConfiguration
import com.namiml.NamiLanguageCode
import com.namiml.NamiLogLevel
import com.namiml.NamiError
import com.namiml.analytics.NamiAnalyticsActionType
import com.namiml.analytics.NamiAnalyticsKeys
import com.namiml.analytics.NamiAnalyticsPurchaseActivityType
import com.namiml.analytics.NamiAnalyticsSupport
import com.namiml.billing.NamiPurchase
import com.namiml.billing.NamiPurchaseCompleteResult
import com.namiml.billing.NamiPurchaseManager
Expand Down Expand Up @@ -40,8 +36,6 @@ import com.namiml.paywall.PreparePaywallError
import com.namiml.paywall.SubscriptionPeriod
import com.namiml.paywall.model.NamiPaywallAction
import com.namiml.campaign.NamiCampaign
import com.namiml.util.extensions.getFormattedPrice
import com.namiml.util.extensions.getSubscriptionPeriodEnum
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
Expand All @@ -65,7 +59,6 @@ class FlutterNamiSdkPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
/// when the Flutter Engine is detached from the Activity
private lateinit var channel: MethodChannel
private lateinit var signInListener: EventChannel
private lateinit var analyticsListener: EventChannel
private lateinit var activeEntitlementsListener: EventChannel
private lateinit var journeyStateListener: EventChannel
private lateinit var purchaseChangeListener: EventChannel
Expand All @@ -77,12 +70,11 @@ class FlutterNamiSdkPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
private lateinit var context: Context
private var currentActivityWeakReference: WeakReference<Activity>? = null

private var paywallActionCallback : ((NamiPaywallAction, NamiSKU?) -> Unit)? = null
private var paywallActionCallback : ((String, String?, String, NamiPaywallAction, NamiSKU?, String?, List<NamiPurchase>?) -> Unit)? = null

override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "nami")
signInListener = EventChannel(flutterPluginBinding.binaryMessenger, "signInEvent")
analyticsListener = EventChannel(flutterPluginBinding.binaryMessenger, "analyticsEvent")
activeEntitlementsListener =
EventChannel(flutterPluginBinding.binaryMessenger, "activeEntitlementsEvent")
purchaseChangeListener =
Expand All @@ -102,7 +94,6 @@ class FlutterNamiSdkPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
channel.setMethodCallHandler(this)
context = flutterPluginBinding.applicationContext
setSignInStreamHandler()
setAnalyticsStreamHandler()
setActiveEntitlementsStreamHandler()
setPurchaseChangeStreamHandler()
setCustomerJourneyStateHandler()
Expand Down Expand Up @@ -147,31 +138,6 @@ class FlutterNamiSdkPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
})
}

private fun setAnalyticsStreamHandler() {
analyticsListener.setStreamHandler(object : StreamHandler(), EventChannel.StreamHandler {
override fun onListen(arguments: Any?, events: EventChannel.EventSink?) {
NamiAnalyticsSupport.registerAnalyticsHandler { namiAnalyticsActionType, map ->
val finalMap = HashMap(map)
finalMap["type"] = namiAnalyticsActionType.getFlutterString()
@Suppress("UNCHECKED_CAST")
val skus = map[NamiAnalyticsKeys.PAYWALL_PRODUCTS] as? List<NamiSKU>
finalMap[NamiAnalyticsKeys.PAYWALL_PRODUCTS] = skus?.map { it.convertToMap() }
val purchasedProduct = map[NamiAnalyticsKeys.PURCHASE_PRODUCT] as? NamiSKU
finalMap[NamiAnalyticsKeys.PURCHASE_PRODUCT] = purchasedProduct?.convertToMap()
val activityType = map[NamiAnalyticsKeys.PURCHASE_ACTIVITY_TYPE]
as? NamiAnalyticsPurchaseActivityType
finalMap[NamiAnalyticsKeys.PURCHASE_ACTIVITY_TYPE] =
activityType?.getFlutterString()
events?.success(finalMap)
}
}

override fun onCancel(arguments: Any?) {
NamiAnalyticsSupport.registerAnalyticsHandler(null)
}
})
}

private fun setActiveEntitlementsStreamHandler() {
activeEntitlementsListener.setStreamHandler(object : StreamHandler(),
EventChannel.StreamHandler {
Expand Down Expand Up @@ -285,12 +251,17 @@ class FlutterNamiSdkPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
paywallActionListener.setStreamHandler(object : StreamHandler(),
EventChannel.StreamHandler {
override fun onListen(arguments: Any?, events: EventChannel.EventSink?) {
paywallActionCallback = { action, sku ->
paywallActionCallback = { campaignId, campaignLabel, paywallId, action, sku, purchaseError, purchases ->
CoroutineScope(Dispatchers.Main).launch {
events?.success(
mapOf(
"campaignId" to campaignId,
"campaignLabel" to campaignLabel,
"paywallId" to paywallId,
"action" to action.name,
"sku" to sku?.convertToMap()
"sku" to sku?.convertToMap(),
"purchaseError" to purchaseError,
"purchases" to purchases?.map { it.convertToMap() }
)
)
}
Expand All @@ -315,8 +286,7 @@ class FlutterNamiSdkPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
}
configure(
context,
call.argument<String>("appPlatformIdGoogle"),
call.argument<Boolean>("bypassStore"),
call.argument<String>("appPlatformIdAndroid"),
namiLogLevel,
call.argument<List<String>>("extraDataList")
)
Expand Down Expand Up @@ -354,16 +324,11 @@ class FlutterNamiSdkPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
result.success(this)
}
}
is LaunchCampaignResult.PurchaseChanged -> {
with(mapOf("success" to true, "error" to null)) {
result.success(this)
}
}
}
}

val actionCallback = { action: NamiPaywallAction, sku: NamiSKU? ->
paywallActionCallback?.invoke(action, sku)
val actionCallback = { campaignId: String, campaignLabel: String?, paywallId: String, action: NamiPaywallAction, sku: NamiSKU?, purchaseError: String?, purchases: List<NamiPurchase>? ->
paywallActionCallback?.invoke(campaignId, campaignLabel, paywallId, action, sku, purchaseError, purchases)
Unit
}

Expand Down Expand Up @@ -393,7 +358,7 @@ class FlutterNamiSdkPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
val label = call.argument<String>("label")
result.success(
if (label != null) {
NamiCampaignManager.isCampaignAvailable(label = label)
NamiCampaignManager.isCampaignAvailable(label)
} else {
NamiCampaignManager.isCampaignAvailable()
}
Expand Down Expand Up @@ -473,16 +438,15 @@ class FlutterNamiSdkPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
private fun configure(
context: Context,
platformId: String?,
bypass: Boolean?,
namiLogLevel: NamiLogLevel,
extraDataList: List<String>?
) {
if (platformId == null) {
return
}

val configuration = NamiConfiguration.build(context, platformId) {
this.logLevel = namiLogLevel
this.bypassStore = bypass ?: false
this.settingsList = extraDataList
}
Nami.configure(configuration)
Expand All @@ -498,7 +462,7 @@ class FlutterNamiSdkPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
}

override fun onDetachedFromActivityForConfigChanges() {
// Do nothing
currentActivityWeakReference = null
}

override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
Expand Down Expand Up @@ -576,19 +540,16 @@ private fun AccountStateAction.getFlutterString(): String {
return when (this) {
AccountStateAction.LOGIN -> "login"
AccountStateAction.LOGOUT -> "logout"
AccountStateAction.ADVERTISING_ID_SET -> "advertising_id_set"
AccountStateAction.ADVERTISING_ID_CLEARED -> "advertising_id_cleared"
AccountStateAction.VENDOR_ID_SET -> "vendor_id_set"
AccountStateAction.VENDOR_ID_CLEARED -> "vendor_id_cleared"
AccountStateAction.CUSTOMER_DATA_PLATFORM_ID_SET -> "customer_data_platform_id_set"
AccountStateAction.CUSTOMER_DATA_PLATFORM_ID_CLEARED -> "customer_data_platform_id_cleared"
else -> "unknown"
}
}

private fun NamiAnalyticsPurchaseActivityType.getFlutterString(): String? {
return when (this) {
NamiAnalyticsPurchaseActivityType.NEW_PURCHASE -> "new_purchase"
NamiAnalyticsPurchaseActivityType.RESTORE -> "restore"
NamiAnalyticsPurchaseActivityType.RESUBSCRIBE -> "resubscribe"
else -> null
}
}

private fun NamiSKU.convertToMap(): Map<String, Any?> {
return hashMapOf(
"name" to this.name,
Expand Down Expand Up @@ -637,15 +598,6 @@ private fun NamiPurchaseState.getFlutterString(): String {
}
}

private fun NamiAnalyticsActionType.getFlutterString(): String {
return when (this) {
NamiAnalyticsActionType.PAYWALL_RAISE -> "paywall_raise"
NamiAnalyticsActionType.PAYWALL_RAISE_BLOCKED -> "paywall_raise_blocked"
NamiAnalyticsActionType.PURCHASE_ACTIVITY -> "purchase_activity"
}
}


private fun LaunchCampaignError.getFlutterString(): String {
return when (this) {
LaunchCampaignError.SDK_NOT_INITIALIZED -> "sdk_not_initialized"
Expand Down
2 changes: 1 addition & 1 deletion sdk/example/testnami/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '1.8.10'
repositories {
google()
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
2 changes: 1 addition & 1 deletion sdk/example/testnami/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
platform :ios, '13.0'
platform :ios, '14.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
4 changes: 3 additions & 1 deletion sdk/example/testnami/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -217,6 +217,7 @@
/* Begin PBXShellScriptBuildPhase section */
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -253,6 +254,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down
2 changes: 1 addition & 1 deletion sdk/example/testnami/lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class TestNamiFlutterAppState extends State<TestNamiFlutterApp>

var namiConfiguration = NamiConfiguration(
appPlatformIdApple: iosAppPlatformId,
appPlatformIdGoogle: androidAppPlatformId,
appPlatformIdAndroid: androidAppPlatformId,
namiLogLevel: NamiLogLevel.debug,
extraData: extraData);
Nami.configure(namiConfiguration);
Expand Down
1 change: 1 addition & 0 deletions sdk/example/testnami/lib/campaign.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class CampaignWidgetState extends State<CampaignWidget> {
? "default"
: campaign.value ?? '',
style: const TextStyle(fontSize: 20),
textAlign: TextAlign.center,
),
),
);
Expand Down
6 changes: 2 additions & 4 deletions sdk/example/testnami/lib/profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ProfileWidgetState extends State<ProfileWidget>
with WidgetsBindingObserver {
List<StreamSubscription> _subscriptions = [];
String _deviceId = "";
String _externalId = "";
String? _externalId;
bool _isLoggedIn = false;

bool _formerSubscriber = false;
Expand All @@ -44,9 +44,7 @@ class ProfileWidgetState extends State<ProfileWidget>

setState(() {
_isLoggedIn = isLoggedIn;
if (loggedInId != null) {
_externalId = loggedInId;
}
_externalId = loggedInId;
print(
"isLoggedIn $_isLoggedIn, loggedInId $_externalId, deviceId $_deviceId");
});
Expand Down
16 changes: 14 additions & 2 deletions sdk/ios/Classes/SwiftFlutterNamiSdkPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public class SwiftFlutterNamiSdkPlugin: NSObject, FlutterPlugin {
public static func register(with registrar: FlutterPluginRegistrar) {
let channel = FlutterMethodChannel(name: "nami", binaryMessenger: registrar.messenger())
let signInEventChannel = FlutterEventChannel(name: "signInEvent", binaryMessenger: registrar.messenger())
let analyticsEventChannel = FlutterEventChannel(name: "analyticsEvent", binaryMessenger: registrar.messenger())
let activeEntitlementsEventChannel = FlutterEventChannel(name: "activeEntitlementsEvent", binaryMessenger: registrar.messenger())
let purchasesChangeEventChannel = FlutterEventChannel(name: "purchasesResponseHandlerData", binaryMessenger: registrar.messenger())
let journeyStateEventChannel = FlutterEventChannel(name: "journeyStateEvent", binaryMessenger: registrar.messenger())
Expand All @@ -23,7 +22,6 @@ public class SwiftFlutterNamiSdkPlugin: NSObject, FlutterPlugin {
let instance = SwiftFlutterNamiSdkPlugin()
registrar.addMethodCallDelegate(instance, channel: channel)
signInEventChannel.setStreamHandler(SignInEventHandler())
analyticsEventChannel.setStreamHandler(AnalyticsEventHandler())
activeEntitlementsEventChannel.setStreamHandler(ActiveEntitlementsEventHandler())
purchasesChangeEventChannel.setStreamHandler(PurchasesChangedEventHandler())
journeyStateEventChannel.setStreamHandler(JourneyStateEventHandler())
Expand Down Expand Up @@ -360,6 +358,18 @@ public extension AccountStateAction {
return "login"
case AccountStateAction.logout:
return "logout"
case AccountStateAction.ADVERTISING_ID_SET:
return "advertising_id_set"
case AccountStateAction.ADVERTISING_ID_CLEARED:
return "advertising_id_cleared"
case AccountStateAction.VENDOR_ID_SET:
return "vendor_id_set"
case AccountStateAction.VENDOR_ID_CLEARED:
return "vendor_id_cleared"
case AccountStateAction.CUSTOMER_DATA_PLATFORM_ID_SET:
return "customer_data_platform_id_set"
case AccountStateAction.CUSTOMER_DATA_PLATFORM_ID_CLEARED:
return "customer_data_platform_id_cleared"
default:
return "unknown"
}
Expand All @@ -369,6 +379,8 @@ public extension AccountStateAction {
public extension NamiPaywallAction {
func toFlutterString() -> String {
switch self {
case NamiPaywallAction.show_paywall:
return "NAMI_SHOW_PAYWALL"
case NamiPaywallAction.close_paywall:
return "NAMI_CLOSE_PAYWALL"
case NamiPaywallAction.restore_purchases:
Expand Down
8 changes: 4 additions & 4 deletions sdk/ios/nami_flutter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
Pod::Spec.new do |s|
s.name = 'nami_flutter'
s.version = '3.0.7'
s.version = '3.0.8'
s.summary = 'Easy subscriptions & in-app purchases for Flutter, with powerful built-in paywalls and A/B testing.'
s.description = <<-DESC
This library helps you offer subscriptions & IAPs for Flutter apps published to the App Store and Google Play.
Expand All @@ -26,13 +26,13 @@ See https://www.namiml.com for more details and to create a free account.
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
s.platform = :ios, '13.0'
s.dependency 'Nami', '3.0.7'
s.platform = :ios, '14.0'
s.dependency 'Nami', '3.0.8'
# s.static_framework = true
# s.preserve_paths = 'Nami.xcframework'
# s.xcconfig = { 'OTHER_LDFLAGS' => '-framework Nami' }

s.vendored_frameworks = 'Nami.xcframework'
s.vendored_frameworks = 'NamiApple.xcframework'

# Flutter.framework does not contain a i386 slice.

Expand Down
Loading

0 comments on commit 9a74455

Please sign in to comment.