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/Sources/Qonversion/Public/Qonversion.m b/Sources/Qonversion/Public/Qonversion.m index 0992e4dc..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 restore: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 3185133e..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)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 ff13371c..cfba7f8a 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,7 +458,34 @@ - (void)processProductPurchase:(QONProduct *)product options:(QONPurchaseOptions run_block_on_main(completion, @{}, [QONErrors errorWithQONErrorCode:QONErrorProductNotFound], NO); } -- (void)restore:(QNRestoreCompletionHandler)completion { +- (void)restoreReceipt:(QNRestoreCompletionHandler)completion { + if (completion) { + [self.receiptRestoreBlocks addObject:completion]; + } + + if (self.receiptRestoreInProgress) { + 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)restoreTransactions:(QNRestoreCompletionHandler)completion { if (completion != nil) { [self.restorePurchasesBlocks addObject:completion]; } 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; 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]; diff --git a/Sources/Qonversion/Qonversion/Utils/QNUserInfo/QNUserInfo.m b/Sources/Qonversion/Qonversion/Utils/QNUserInfo/QNUserInfo.m index d1462129..8269ff6c 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,15 @@ + (BOOL)isDebug { } + (nullable NSBundle *)bundle { - NSPredicate *predicate = [NSPredicate predicateWithFormat:@"appStoreReceiptURL != nil"]; - return [NSBundle.allBundles filteredArrayUsingPredicate:predicate].firstObject; + NSArray *allBundles = [[NSBundle allBundles] copy]; + + for (NSBundle *bundle in allBundles) { + if (bundle.appStoreReceiptURL != nil) { + return bundle; + } + } + + return nil; } @end 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 @@ - + - +