From 28d5655977d132a9d621be9d8e67cae1ce89f049 Mon Sep 17 00:00:00 2001 From: Surik Date: Fri, 6 Sep 2024 15:58:10 +0400 Subject: [PATCH 1/6] Added extra check to interger mapping --- Sources/Qonversion/Qonversion/Mappers/QNMapper/QNMapper.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Qonversion/Qonversion/Mappers/QNMapper/QNMapper.m b/Sources/Qonversion/Qonversion/Mappers/QNMapper/QNMapper.m index 4eb945bb..1cdabebc 100644 --- a/Sources/Qonversion/Qonversion/Mappers/QNMapper/QNMapper.m +++ b/Sources/Qonversion/Qonversion/Mappers/QNMapper/QNMapper.m @@ -408,13 +408,13 @@ + (QNMapperObject *)mapperObjectFrom:(NSDictionary *)dict { } + (NSInteger)mapInteger:(NSObject *)object orReturn:(NSInteger)defaultValue { - if (object == nil) { + if (!object) { return defaultValue; } NSNumber *numberObject = (NSNumber *)object; - if ([numberObject isEqual:[NSNull null]]) { + if ([numberObject isEqual:[NSNull null]] || ![numberObject respondsToSelector:@selector(integerValue)]) { return defaultValue; } else { return numberObject.integerValue; From 9fa7e4f44c77ceca44a0845d15e97a0436450db5 Mon Sep 17 00:00:00 2001 From: Surik Date: Fri, 6 Sep 2024 19:38:07 +0400 Subject: [PATCH 2/6] Updated restore logic --- Sources/Qonversion/Public/Qonversion.m | 2 +- .../QNProductCenterManager.h | 2 +- .../QNProductCenterManager.m | 27 +++++++++++++++++++ .../QNStoreKitService/QNStoreKitService.m | 1 + 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Sources/Qonversion/Public/Qonversion.m b/Sources/Qonversion/Public/Qonversion.m index 0992e4dc..7aab3022 100644 --- a/Sources/Qonversion/Public/Qonversion.m +++ b/Sources/Qonversion/Public/Qonversion.m @@ -181,7 +181,7 @@ - (void)purchase:(NSString *)productID completion:(QONPurchaseCompletionHandler) } - (void)restore:(QNRestoreCompletionHandler)completion { - [self.productCenterManager restore:completion]; + [self.productCenterManager receiptRestore:completion]; } - (void)products:(QONProductsCompletionHandler)completion { diff --git a/Sources/Qonversion/Qonversion/Main/QNProductCenterManager/QNProductCenterManager.h b/Sources/Qonversion/Qonversion/Main/QNProductCenterManager/QNProductCenterManager.h index 3185133e..7c511da0 100644 --- a/Sources/Qonversion/Qonversion/Main/QNProductCenterManager/QNProductCenterManager.h +++ b/Sources/Qonversion/Qonversion/Main/QNProductCenterManager/QNProductCenterManager.h @@ -38,7 +38,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)userInfo:(QONUserInfoCompletionHandler)completion; - (void)handlePurchases:(NSArray *)purchasesInfo completion:(QONDefaultCompletionHandler)completion; - +- (void)receiptRestore:(QNRestoreCompletionHandler)completion; - (void)launch:(void (^)(QONLaunchResult * _Nullable result, NSError * _Nullable error))completion; - (void)getPromotionalOfferForProduct:(QONProduct *)product discount:(SKProductDiscount *)discount diff --git a/Sources/Qonversion/Qonversion/Main/QNProductCenterManager/QNProductCenterManager.m b/Sources/Qonversion/Qonversion/Main/QNProductCenterManager/QNProductCenterManager.m index ff13371c..3bec52a7 100644 --- a/Sources/Qonversion/Qonversion/Main/QNProductCenterManager/QNProductCenterManager.m +++ b/Sources/Qonversion/Qonversion/Main/QNProductCenterManager/QNProductCenterManager.m @@ -49,6 +49,7 @@ @interface QNProductCenterManager() @property (nonatomic, strong) NSMutableDictionary *purchasingBlocks; @property (nonatomic, strong) NSMutableArray *restorePurchasesBlocks; +@property (nonatomic, strong) NSMutableArray *receiptRestoreBlocks; @property (nonatomic, strong) NSMutableArray *entitlementsBlocks; @property (nonatomic, strong) NSMutableArray *productsBlocks; @property (nonatomic, strong) NSMutableArray *offeringsBlocks; @@ -67,6 +68,7 @@ @interface QNProductCenterManager() @property (nonatomic, assign) BOOL launchingFinished; @property (nonatomic, assign) BOOL productsLoading; @property (nonatomic, assign) BOOL restoreInProgress; +@property (nonatomic, assign) BOOL receiptRestoreInProgress; @property (nonatomic, assign) BOOL awaitingRestoreResult; @property (nonatomic, assign) BOOL identityInProgress; @property (nonatomic, assign) BOOL unhandledLogoutAvailable; @@ -104,6 +106,7 @@ - (instancetype)initWithUserInfoService:(id)userInfo _purchasingBlocks = [NSMutableDictionary new]; _restorePurchasesBlocks = [NSMutableArray new]; + _receiptRestoreBlocks = [NSMutableArray new]; _entitlementsBlocks = [NSMutableArray new]; _productsBlocks = [NSMutableArray new]; _offeringsBlocks = [NSMutableArray new]; @@ -455,6 +458,30 @@ - (void)processProductPurchase:(QONProduct *)product options:(QONPurchaseOptions run_block_on_main(completion, @{}, [QONErrors errorWithQONErrorCode:QONErrorProductNotFound], NO); } +- (void)receiptRestore:(QNRestoreCompletionHandler)completion { + if (self.receiptRestoreInProgress && completion) { + [self.receiptRestoreBlocks addObject:completion]; + return; + } + + self.receiptRestoreInProgress = YES; + + __block __weak QNProductCenterManager *weakSelf = self; + [self.storeKitService receipt:^(NSString * _Nonnull receipt) { + [weakSelf launchWithCompletion:^(QONLaunchResult * _Nonnull result, NSError * _Nullable error) { + @synchronized (weakSelf) { + weakSelf.receiptRestoreInProgress = NO; + NSArray *completions = [self.receiptRestoreBlocks copy]; + [weakSelf.receiptRestoreBlocks removeAllObjects]; + + for (QONEntitlementsCompletionHandler block in completions) { + run_block_on_main(block, result.entitlements, error); + } + } + }]; + }]; +} + - (void)restore:(QNRestoreCompletionHandler)completion { if (completion != nil) { [self.restorePurchasesBlocks addObject:completion]; diff --git a/Sources/Qonversion/Qonversion/Services/QNStoreKitService/QNStoreKitService.m b/Sources/Qonversion/Qonversion/Services/QNStoreKitService/QNStoreKitService.m index d8e1cada..004458d1 100644 --- a/Sources/Qonversion/Qonversion/Services/QNStoreKitService/QNStoreKitService.m +++ b/Sources/Qonversion/Qonversion/Services/QNStoreKitService/QNStoreKitService.m @@ -427,6 +427,7 @@ - (SKReceiptRefreshRequest *)buildReceiptRefreshRequest { - (void)finishReceiptFetchRequest:(SKRequest *)request { @synchronized(self) { + [self.receiptRefreshRequest cancel]; self.receiptRefreshRequest = nil; NSArray *handlers = [self.receiptRefreshCompletionHandlers copy]; [self.receiptRefreshCompletionHandlers removeAllObjects]; From 673c1676f3bcd2c8f8ef5df6a75a369fd7f6628f Mon Sep 17 00:00:00 2001 From: Surik Date: Mon, 9 Sep 2024 18:09:50 +0400 Subject: [PATCH 3/6] Review fixes --- Sources/Qonversion/Public/Qonversion.m | 2 +- .../Main/QNProductCenterManager/QNProductCenterManager.h | 4 ++-- .../Main/QNProductCenterManager/QNProductCenterManager.m | 9 ++++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Sources/Qonversion/Public/Qonversion.m b/Sources/Qonversion/Public/Qonversion.m index 7aab3022..173dd53a 100644 --- a/Sources/Qonversion/Public/Qonversion.m +++ b/Sources/Qonversion/Public/Qonversion.m @@ -181,7 +181,7 @@ - (void)purchase:(NSString *)productID completion:(QONPurchaseCompletionHandler) } - (void)restore:(QNRestoreCompletionHandler)completion { - [self.productCenterManager receiptRestore:completion]; + [self.productCenterManager restoreReceipt:completion]; } - (void)products:(QONProductsCompletionHandler)completion { diff --git a/Sources/Qonversion/Qonversion/Main/QNProductCenterManager/QNProductCenterManager.h b/Sources/Qonversion/Qonversion/Main/QNProductCenterManager/QNProductCenterManager.h index 7c511da0..2de1ca52 100644 --- a/Sources/Qonversion/Qonversion/Main/QNProductCenterManager/QNProductCenterManager.h +++ b/Sources/Qonversion/Qonversion/Main/QNProductCenterManager/QNProductCenterManager.h @@ -29,7 +29,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)checkEntitlements:(QONEntitlementsCompletionHandler)completion; - (void)purchase:(QONProduct * _Nonnull)product options:(QONPurchaseOptions * _Nullable)options completion:(nonnull QONPurchaseCompletionHandler)completion; - (void)purchase:(NSString * _Nonnull)productID purchaseOptions:(QONPurchaseOptions * _Nullable)options completion:(nonnull QONPurchaseCompletionHandler)completion; -- (void)restore:(QNRestoreCompletionHandler)completion; +- (void)restoreTransactions:(QNRestoreCompletionHandler)completion; - (void)products:(QONProductsCompletionHandler)completion; - (void)checkTrialIntroEligibilityForProductIds:(NSArray *)productIds completion:(QONEligibilityCompletionHandler)completion; @@ -38,7 +38,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)userInfo:(QONUserInfoCompletionHandler)completion; - (void)handlePurchases:(NSArray *)purchasesInfo completion:(QONDefaultCompletionHandler)completion; -- (void)receiptRestore:(QNRestoreCompletionHandler)completion; +- (void)restoreReceipt:(QNRestoreCompletionHandler)completion; - (void)launch:(void (^)(QONLaunchResult * _Nullable result, NSError * _Nullable error))completion; - (void)getPromotionalOfferForProduct:(QONProduct *)product discount:(SKProductDiscount *)discount diff --git a/Sources/Qonversion/Qonversion/Main/QNProductCenterManager/QNProductCenterManager.m b/Sources/Qonversion/Qonversion/Main/QNProductCenterManager/QNProductCenterManager.m index 3bec52a7..cfba7f8a 100644 --- a/Sources/Qonversion/Qonversion/Main/QNProductCenterManager/QNProductCenterManager.m +++ b/Sources/Qonversion/Qonversion/Main/QNProductCenterManager/QNProductCenterManager.m @@ -458,9 +458,12 @@ - (void)processProductPurchase:(QONProduct *)product options:(QONPurchaseOptions run_block_on_main(completion, @{}, [QONErrors errorWithQONErrorCode:QONErrorProductNotFound], NO); } -- (void)receiptRestore:(QNRestoreCompletionHandler)completion { - if (self.receiptRestoreInProgress && completion) { +- (void)restoreReceipt:(QNRestoreCompletionHandler)completion { + if (completion) { [self.receiptRestoreBlocks addObject:completion]; + } + + if (self.receiptRestoreInProgress) { return; } @@ -482,7 +485,7 @@ - (void)receiptRestore:(QNRestoreCompletionHandler)completion { }]; } -- (void)restore:(QNRestoreCompletionHandler)completion { +- (void)restoreTransactions:(QNRestoreCompletionHandler)completion { if (completion != nil) { [self.restorePurchasesBlocks addObject:completion]; } From e3f0c74411beba244a8dfad78a985a42f564a550 Mon Sep 17 00:00:00 2001 From: Surik Date: Mon, 9 Sep 2024 19:05:34 +0400 Subject: [PATCH 4/6] FIxed bundle fetching logic --- .../Qonversion/Utils/QNUserInfo/QNUserInfo.m | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Sources/Qonversion/Qonversion/Utils/QNUserInfo/QNUserInfo.m b/Sources/Qonversion/Qonversion/Utils/QNUserInfo/QNUserInfo.m index d1462129..1e983d25 100644 --- a/Sources/Qonversion/Qonversion/Utils/QNUserInfo/QNUserInfo.m +++ b/Sources/Qonversion/Qonversion/Utils/QNUserInfo/QNUserInfo.m @@ -73,7 +73,8 @@ + (NSDictionary *)overallData { } + (nullable NSString *)appStoreReceipt { - NSURL *receiptURL = QNUserInfo.bundle.appStoreReceiptURL; + NSURL *tempReceiptURL = QNUserInfo.bundle.appStoreReceiptURL; + NSURL *receiptURL = tempReceiptURL ?: [NSBundle mainBundle].appStoreReceiptURL; if (!receiptURL) { return @""; @@ -95,8 +96,16 @@ + (BOOL)isDebug { } + (nullable NSBundle *)bundle { - NSPredicate *predicate = [NSPredicate predicateWithFormat:@"appStoreReceiptURL != nil"]; - return [NSBundle.allBundles filteredArrayUsingPredicate:predicate].firstObject; + NSArray *allBundles = [[NSBundle allBundles] copy]; + NSMutableArray *filteredBundles = [NSMutableArray new]; + + for (NSBundle *bundle in allBundles) { + if (bundle.appStoreReceiptURL != nil) { + [filteredBundles addObject:bundle]; + } + } + + return filteredBundles.firstObject; } @end From fcb5bf226b009a07332fb50e2f53c39392c77988 Mon Sep 17 00:00:00 2001 From: Surik Date: Mon, 9 Sep 2024 19:10:42 +0400 Subject: [PATCH 5/6] Updated logic --- Sources/Qonversion/Qonversion/Utils/QNUserInfo/QNUserInfo.m | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Sources/Qonversion/Qonversion/Utils/QNUserInfo/QNUserInfo.m b/Sources/Qonversion/Qonversion/Utils/QNUserInfo/QNUserInfo.m index 1e983d25..8269ff6c 100644 --- a/Sources/Qonversion/Qonversion/Utils/QNUserInfo/QNUserInfo.m +++ b/Sources/Qonversion/Qonversion/Utils/QNUserInfo/QNUserInfo.m @@ -97,15 +97,14 @@ + (BOOL)isDebug { + (nullable NSBundle *)bundle { NSArray *allBundles = [[NSBundle allBundles] copy]; - NSMutableArray *filteredBundles = [NSMutableArray new]; for (NSBundle *bundle in allBundles) { if (bundle.appStoreReceiptURL != nil) { - [filteredBundles addObject:bundle]; + return bundle; } } - return filteredBundles.firstObject; + return nil; } @end From 2553717fd61782d443aba4e1290c110e8274568f Mon Sep 17 00:00:00 2001 From: suriksarkisyan Date: Mon, 9 Sep 2024 16:54:01 +0000 Subject: [PATCH 6/6] [create-pull-request] automated change --- Framework/Info.plist | 2 +- Qonversion.podspec | 2 +- Sources/Qonversion/Public/QONConfiguration.m | 2 +- fastlane/report.xml | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Framework/Info.plist b/Framework/Info.plist index 92eae326..132f358f 100644 --- a/Framework/Info.plist +++ b/Framework/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 5.12.1 + 5.12.2 CFBundleSignature ???? CFBundleVersion diff --git a/Qonversion.podspec b/Qonversion.podspec index 7284dfbb..4bf013d2 100644 --- a/Qonversion.podspec +++ b/Qonversion.podspec @@ -3,7 +3,7 @@ Pod::Spec.new do |s| idfa_exclude_files = ['Sources/Qonversion/IDFA'] s.name = 'Qonversion' s.swift_version = '5.5' - s.version = '5.12.1' + s.version = '5.12.2' s.summary = 'qonversion.io' s.description = <<-DESC Deep Analytics for iOS Subscriptions diff --git a/Sources/Qonversion/Public/QONConfiguration.m b/Sources/Qonversion/Public/QONConfiguration.m index c7601bb6..db105fbf 100644 --- a/Sources/Qonversion/Public/QONConfiguration.m +++ b/Sources/Qonversion/Public/QONConfiguration.m @@ -9,7 +9,7 @@ #import "QONConfiguration.h" #import "QNAPIConstants.h" -static NSString *const kSDKVersion = @"5.12.1"; +static NSString *const kSDKVersion = @"5.12.2"; @interface QONConfiguration () diff --git a/fastlane/report.xml b/fastlane/report.xml index b012ee27..8a14e059 100644 --- a/fastlane/report.xml +++ b/fastlane/report.xml @@ -5,12 +5,12 @@ - + - +