Skip to content

Commit

Permalink
Merge pull request #47 from apphud/feature/skproduct-extension
Browse files Browse the repository at this point in the history
feat: created changes for skproduct
  • Loading branch information
alexandr-makarov-am authored Oct 31, 2022
2 parents 21cbaf1 + 8be15eb commit 0df8605
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 27 deletions.
9 changes: 5 additions & 4 deletions example/ios/ApphudSdkExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@
TestTargetID = 13B07F861A680F5B00A75B9A;
};
13B07F861A680F5B00A75B9A = {
DevelopmentTeam = JLG6CF288G;
LastSwiftMigration = 1120;
};
2D02E47A1E0B4A5D006451C7 = {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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";
Expand All @@ -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";
Expand Down
30 changes: 15 additions & 15 deletions example/ios/ApphudSdkExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,7 @@
</dict>
</dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<string></string>
<key>UIAppFonts</key>
<array>
<string>AntDesign.ttf</string>
Expand All @@ -72,5 +58,19 @@
<string>SimpleLineIcons.ttf</string>
<string>Zocial.ttf</string>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
</dict>
</plist>
59 changes: 53 additions & 6 deletions ios/DataTransformer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,61 @@ 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.floatValue,
"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 ?? "",
"countryCode": regionCode ?? "",
]
}
}

@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.floatValue,
"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 {
Expand Down
11 changes: 9 additions & 2 deletions src/ApphudSdkType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,24 @@ export interface RestorePurchase {
export interface ApphudProduct {
id: string;
price: string;
localizeTitle?: string;
localizedDescription?: string;
priceLocale?: {
currencySymbol: string;
currencyCode: string;
countryCode: string;
};
subscriptionPeriod?: any;
introductoryPrice?: 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;
Expand Down

0 comments on commit 0df8605

Please sign in to comment.