From ba771f7d9c7b362055ec2f86051e7ac53ea44748 Mon Sep 17 00:00:00 2001 From: Alexandr Makarov Date: Tue, 25 Oct 2022 10:45:22 +0300 Subject: [PATCH 1/3] feat: created changes for skproduct --- .../project.pbxproj | 9 +-- example/ios/ApphudSdkExample/Info.plist | 30 +++++----- ios/DataTransformer.swift | 58 +++++++++++++++++-- src/ApphudSdkType.ts | 14 ++++- 4 files changed, 84 insertions(+), 27 deletions(-) diff --git a/example/ios/ApphudSdkExample.xcodeproj/project.pbxproj b/example/ios/ApphudSdkExample.xcodeproj/project.pbxproj index d8bbdac..69a4679 100644 --- a/example/ios/ApphudSdkExample.xcodeproj/project.pbxproj +++ b/example/ios/ApphudSdkExample.xcodeproj/project.pbxproj @@ -309,6 +309,7 @@ TestTargetID = 13B07F861A680F5B00A75B9A; }; 13B07F861A680F5B00A75B9A = { + DevelopmentTeam = JLG6CF288G; LastSwiftMigration = 1120; }; 2D02E47A1E0B4A5D006451C7 = { @@ -617,7 +618,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = JLG6CF288G; ENABLE_BITCODE = NO; INFOPLIST_FILE = ApphudSdkExample/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 11.2; @@ -631,7 +632,7 @@ "-ObjC", "-lc++", ); - PRODUCT_BUNDLE_IDENTIFIER = com.touchzoo.livepapers; + PRODUCT_BUNDLE_IDENTIFIER = com.apphud.testapplication; PRODUCT_NAME = ApphudSdkExample; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; @@ -646,7 +647,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = JLG6CF288G; INFOPLIST_FILE = ApphudSdkExample/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 11.2; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -659,7 +660,7 @@ "-ObjC", "-lc++", ); - PRODUCT_BUNDLE_IDENTIFIER = com.touchzoo.livepapers; + PRODUCT_BUNDLE_IDENTIFIER = com.apphud.testapplication; PRODUCT_NAME = ApphudSdkExample; SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; diff --git a/example/ios/ApphudSdkExample/Info.plist b/example/ios/ApphudSdkExample/Info.plist index 16a92e9..dab6c5d 100644 --- a/example/ios/ApphudSdkExample/Info.plist +++ b/example/ios/ApphudSdkExample/Info.plist @@ -38,21 +38,7 @@ NSLocationWhenInUseUsageDescription - - UILaunchStoryboardName - LaunchScreen - UIRequiredDeviceCapabilities - - armv7 - - UISupportedInterfaceOrientations - - UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - UIViewControllerBasedStatusBarAppearance - + UIAppFonts AntDesign.ttf @@ -72,5 +58,19 @@ SimpleLineIcons.ttf Zocial.ttf + UILaunchStoryboardName + LaunchScreen + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UIViewControllerBasedStatusBarAppearance + diff --git a/ios/DataTransformer.swift b/ios/DataTransformer.swift index 6212325..646d12e 100644 --- a/ios/DataTransformer.swift +++ b/ios/DataTransformer.swift @@ -9,14 +9,60 @@ import Foundation import StoreKit import ApphudSDK +extension SKProduct { + func toMap() -> NSDictionary { + let map: NSDictionary = [ + "id": productIdentifier, + "localizedTitle": localizedTitle, + "localizedDescription": localizedDescription, + "priceLocale": priceLocale.toMap(), + "price": price.description, + "subscriptionPeriod": subscriptionPeriod?.toMap() as Any, + "introductoryPrice": introductoryPrice?.toMap() as Any, + "isDownloadable": isDownloadable, + "downloadContentLengths": downloadContentLengths.map {$0.intValue}, + "contentVersion": contentVersion, + "downloadContentVersion": downloadContentVersion + ] + return map + } +} + +extension Locale { + func toMap() -> NSDictionary { + return [ + "currencySymbol": currencySymbol ?? "", + "currencyCode": currencyCode ?? "" + ] + } +} + +@available(iOS 11.2, *) +extension SKProductSubscriptionPeriod { + func toMap() -> NSDictionary { + return [ + "numberOfUnits": numberOfUnits, + "unit": unit.rawValue + ] + } +} + +@available(iOS 11.2, *) +extension SKProductDiscount { + func toMap() -> NSDictionary { + return [ + "price": price.description, + "priceLocale": ["":""], + "numberOfPeriods": numberOfPeriods, + "subscriptionPeriod": subscriptionPeriod.toMap(), + "paymentMode": paymentMode.rawValue, + ] + } +} + public class DataTransformer { public static func skProduct(product: SKProduct) -> NSDictionary { - return [ - "id": product.productIdentifier, - "price": product.price, - "regionCode": product.priceLocale.regionCode as Any, - "currencyCode": product.priceLocale.currencyCode as Any, - ]; + return product.toMap(); } public static func apphudSubscription(subscription: ApphudSubscription?) -> NSDictionary { diff --git a/src/ApphudSdkType.ts b/src/ApphudSdkType.ts index 0d628e5..e4ad0f9 100644 --- a/src/ApphudSdkType.ts +++ b/src/ApphudSdkType.ts @@ -83,17 +83,27 @@ export interface RestorePurchase { export interface ApphudProduct { id: string; price: string; + localizeTitle?: string; + localizedDescription?: string; + priceLocale?: { + currencySymbol: string; + currencyCode: string; + }; + subscriptionPeriod?: any; + introductoryPrice?: any; + isDownloadable?: boolean; + downloadContentLengths?: any; + contentVersion?: any; + downloadContentVersion?: any; regionCode?: string; currencyCode?: string; description?: string; freeTrialPeriod?: string; - introductoryPrice?: string; introductoryPriceAmountMicros?: number; introductoryPriceCycles?: number; introductoryPricePeriod?: string; priceAmountMicros?: number; priceCurrencyCode?: string; - subscriptionPeriod?: string; title?: string; originalPrice?: string; type?: string; From 604c7e924bf4d300b45af13d7bc5f234225798df Mon Sep 17 00:00:00 2001 From: Alexandr Makarov Date: Thu, 27 Oct 2022 11:27:42 +0300 Subject: [PATCH 2/3] fix: set changes for skproduct type --- ios/DataTransformer.swift | 13 +++++++------ src/ApphudSdkType.ts | 5 +---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/ios/DataTransformer.swift b/ios/DataTransformer.swift index 646d12e..8acc1f7 100644 --- a/ios/DataTransformer.swift +++ b/ios/DataTransformer.swift @@ -19,10 +19,10 @@ extension SKProduct { "price": price.description, "subscriptionPeriod": subscriptionPeriod?.toMap() as Any, "introductoryPrice": introductoryPrice?.toMap() as Any, - "isDownloadable": isDownloadable, - "downloadContentLengths": downloadContentLengths.map {$0.intValue}, - "contentVersion": contentVersion, - "downloadContentVersion": downloadContentVersion + //"isDownloadable": isDownloadable, + //"downloadContentLengths": downloadContentLengths.map {$0.intValue}, + //"contentVersion": contentVersion, + //"downloadContentVersion": downloadContentVersion ] return map } @@ -32,7 +32,8 @@ extension Locale { func toMap() -> NSDictionary { return [ "currencySymbol": currencySymbol ?? "", - "currencyCode": currencyCode ?? "" + "currencyCode": currencyCode ?? "", + "countryCode": regionCode ?? "", ] } } @@ -51,7 +52,7 @@ extension SKProductSubscriptionPeriod { extension SKProductDiscount { func toMap() -> NSDictionary { return [ - "price": price.description, + "price": price.floatValue, "priceLocale": ["":""], "numberOfPeriods": numberOfPeriods, "subscriptionPeriod": subscriptionPeriod.toMap(), diff --git a/src/ApphudSdkType.ts b/src/ApphudSdkType.ts index e4ad0f9..eeaa3ec 100644 --- a/src/ApphudSdkType.ts +++ b/src/ApphudSdkType.ts @@ -88,13 +88,10 @@ export interface ApphudProduct { priceLocale?: { currencySymbol: string; currencyCode: string; + countryCode: string; }; subscriptionPeriod?: any; introductoryPrice?: any; - isDownloadable?: boolean; - downloadContentLengths?: any; - contentVersion?: any; - downloadContentVersion?: any; regionCode?: string; currencyCode?: string; description?: string; From 8be15eb6c0c6a34cd772127e36f49951ca0771eb Mon Sep 17 00:00:00 2001 From: Alexandr Makarov Date: Thu, 27 Oct 2022 11:30:02 +0300 Subject: [PATCH 3/3] fix: set changes for skproduct type --- ios/DataTransformer.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/DataTransformer.swift b/ios/DataTransformer.swift index 8acc1f7..bf6eb0c 100644 --- a/ios/DataTransformer.swift +++ b/ios/DataTransformer.swift @@ -16,7 +16,7 @@ extension SKProduct { "localizedTitle": localizedTitle, "localizedDescription": localizedDescription, "priceLocale": priceLocale.toMap(), - "price": price.description, + "price": price.floatValue, "subscriptionPeriod": subscriptionPeriod?.toMap() as Any, "introductoryPrice": introductoryPrice?.toMap() as Any, //"isDownloadable": isDownloadable,