From d3d42f93db5aa49edde739319c2bd09b2f7b6d88 Mon Sep 17 00:00:00 2001 From: Sam Mejlumyan Date: Mon, 13 Apr 2020 18:30:03 +0300 Subject: [PATCH 1/8] Add country code --- Qonversion.xcodeproj/project.pbxproj | 6 +++--- .../QonversionCheckResult+Protected.h | 0 .../{QonversionCheckResult => }/QonversionCheckResult.h | 0 .../{QonversionCheckResult => }/QonversionCheckResult.m | 0 Sources/Qonversion.m | 8 ++++++++ 5 files changed, 11 insertions(+), 3 deletions(-) rename Sources/Network/Models/{QonversionCheckResult => }/QonversionCheckResult+Protected.h (100%) rename Sources/Network/Models/{QonversionCheckResult => }/QonversionCheckResult.h (100%) rename Sources/Network/Models/{QonversionCheckResult => }/QonversionCheckResult.m (100%) diff --git a/Qonversion.xcodeproj/project.pbxproj b/Qonversion.xcodeproj/project.pbxproj index d0401d56..d48d8552 100644 --- a/Qonversion.xcodeproj/project.pbxproj +++ b/Qonversion.xcodeproj/project.pbxproj @@ -232,7 +232,7 @@ 459DABEC243E35BC0011ECF3 /* Models */ = { isa = PBXGroup; children = ( - 459DAC12243E61BF0011ECF3 /* QonversionCheckResult */, + 45BA20412444BA490046E6C9 /* QonversionCheckResult */, 459DAC11243E61A80011ECF3 /* RenewalProductDetails */, ); path = Models; @@ -275,14 +275,14 @@ name = RenewalProductDetails; sourceTree = ""; }; - 459DAC12243E61BF0011ECF3 /* QonversionCheckResult */ = { + 45BA20412444BA490046E6C9 /* QonversionCheckResult */ = { isa = PBXGroup; children = ( 459DABF0243E35BC0011ECF3 /* QonversionCheckResult.h */, 459DABF2243E35BC0011ECF3 /* QonversionCheckResult+Protected.h */, 459DABED243E35BC0011ECF3 /* QonversionCheckResult.m */, ); - path = QonversionCheckResult; + name = QonversionCheckResult; sourceTree = ""; }; 45CC2EF1244085E4005CD107 /* .github */ = { diff --git a/Sources/Network/Models/QonversionCheckResult/QonversionCheckResult+Protected.h b/Sources/Network/Models/QonversionCheckResult+Protected.h similarity index 100% rename from Sources/Network/Models/QonversionCheckResult/QonversionCheckResult+Protected.h rename to Sources/Network/Models/QonversionCheckResult+Protected.h diff --git a/Sources/Network/Models/QonversionCheckResult/QonversionCheckResult.h b/Sources/Network/Models/QonversionCheckResult.h similarity index 100% rename from Sources/Network/Models/QonversionCheckResult/QonversionCheckResult.h rename to Sources/Network/Models/QonversionCheckResult.h diff --git a/Sources/Network/Models/QonversionCheckResult/QonversionCheckResult.m b/Sources/Network/Models/QonversionCheckResult.m similarity index 100% rename from Sources/Network/Models/QonversionCheckResult/QonversionCheckResult.m rename to Sources/Network/Models/QonversionCheckResult.m diff --git a/Sources/Qonversion.m b/Sources/Qonversion.m index e1007a91..2faa85fe 100644 --- a/Sources/Qonversion.m +++ b/Sources/Qonversion.m @@ -162,6 +162,14 @@ + (void)serviceLogPurchase:(SKProduct *)product transaction:(SKPaymentTransactio } + if (@available(iOS 13.0, *)) { + NSString *countryCode = SKPaymentQueue.defaultQueue.storefront.countryCode ?: @""; + + if (countryCode.length > 0) { + inappDict[@"country"] = countryCode; + } + } + NSDictionary *body = @{@"inapp": inappDict, @"d": UserInfo.overallData}; NSURLRequest *request = [self makePostRequestWithEndpoint:kPurchaseEndpoint andBody:body]; From a362871a44adbbf234067a020340c672cee6c72b Mon Sep 17 00:00:00 2001 From: Sam Mejlumyan Date: Mon, 20 Apr 2020 15:32:28 +0300 Subject: [PATCH 2/8] Add debug mode function --- Sources/Qonversion.h | 8 ++++++++ Sources/Qonversion.m | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/Sources/Qonversion.h b/Sources/Qonversion.h index 69ce9dce..49976b46 100644 --- a/Sources/Qonversion.h +++ b/Sources/Qonversion.h @@ -11,6 +11,14 @@ typedef NS_ENUM(NSInteger, QAttributionProvider) { @interface Qonversion : NSObject +/** + Sets the environment for receipt. + @param debugMode true If your app run under debug mode, default: false + @see [Setting Debug Mode](https://docs.qonversion.io/getting-started/debug-mode) + */ + ++ (void)setDebugMode:(BOOL) debugMode; + + (void)launchWithKey:(nonnull NSString *)key autoTrackPurchases:(BOOL)autoTrack DEPRECATED_MSG_ATTRIBUTE("Use `launchWithKey:completion:` or `launchWithKey:autoTrackPurchases:completion:` method instead."); diff --git a/Sources/Qonversion.m b/Sources/Qonversion.m index 2faa85fe..8352bee3 100644 --- a/Sources/Qonversion.m +++ b/Sources/Qonversion.m @@ -306,4 +306,8 @@ + (NSURLSession *)session { return [NSURLSession sessionWithConfiguration:NSURLSessionConfiguration.defaultSessionConfiguration];; } ++ (void)setDebugMode:(BOOL) debugMode { + +} + @end From c589152fcc56dea3722a53d41390b3ccafb90cf3 Mon Sep 17 00:00:00 2001 From: Sam Mejlumyan Date: Mon, 20 Apr 2020 15:33:15 +0300 Subject: [PATCH 3/8] Remove deprecated method --- Sources/Qonversion.h | 3 --- Sources/Qonversion.m | 6 ------ 2 files changed, 9 deletions(-) diff --git a/Sources/Qonversion.h b/Sources/Qonversion.h index 49976b46..8fd53beb 100644 --- a/Sources/Qonversion.h +++ b/Sources/Qonversion.h @@ -19,9 +19,6 @@ typedef NS_ENUM(NSInteger, QAttributionProvider) { + (void)setDebugMode:(BOOL) debugMode; -+ (void)launchWithKey:(nonnull NSString *)key autoTrackPurchases:(BOOL)autoTrack -DEPRECATED_MSG_ATTRIBUTE("Use `launchWithKey:completion:` or `launchWithKey:autoTrackPurchases:completion:` method instead."); - /** Launches Qonversion SDK with the given project key, you can get one in your account on qonversion.io. @param key - project key to setup the SDK. diff --git a/Sources/Qonversion.m b/Sources/Qonversion.m index 8352bee3..4c85a71c 100644 --- a/Sources/Qonversion.m +++ b/Sources/Qonversion.m @@ -24,12 +24,6 @@ @implementation Qonversion // MARK: - Public -+ (void)launchWithKey:(nonnull NSString *)key autoTrackPurchases:(BOOL)autoTrack { - [self launchWithKey:key autoTrackPurchases:autoTrack completion:^(NSString * _Nonnull uid) { - // dummy - }]; -} - + (void)launchWithKey:(nonnull NSString *)key completion:(nullable void (^)(NSString *uid))completion { [self launchWithKey:key autoTrackPurchases:YES completion:completion]; } From b1db1441894d5ff86e2d715fb922eb15669be7ab Mon Sep 17 00:00:00 2001 From: Sam Mejlumyan Date: Mon, 20 Apr 2020 15:49:18 +0300 Subject: [PATCH 4/8] Add helper for converting data to json --- QonversionTests/Helpers/XCTestCase+TestJSON.m | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/QonversionTests/Helpers/XCTestCase+TestJSON.m b/QonversionTests/Helpers/XCTestCase+TestJSON.m index 9cc7e718..64a37789 100644 --- a/QonversionTests/Helpers/XCTestCase+TestJSON.m +++ b/QonversionTests/Helpers/XCTestCase+TestJSON.m @@ -4,8 +4,8 @@ @implementation XCTestCase (TestJSON) - (id)JSONObjectFromContentsOfFile:(NSString *)filePath { NSData *fileData = [self fileDataFromContentsOfFile:filePath]; - NSDictionary *object = [NSJSONSerialization JSONObjectWithData:fileData options:kNilOptions error:nil]; - return object; + + return [NSJSONSerialization JSONObjectWithData:fileData options:kNilOptions error:nil]; } - (id)fileDataFromContentsOfFile:(NSString *)filePath { @@ -18,4 +18,8 @@ - (id)fileDataFromContentsOfFile:(NSString *)filePath { return [NSData dataWithContentsOfFile:pathToFile]; } +- (id)JSONObjectFromData:(NSData *)data { + return [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil]; +} + @end From f8731f1adf6f7cd746a762a728c272441383207e Mon Sep 17 00:00:00 2001 From: Sam Mejlumyan Date: Mon, 20 Apr 2020 15:49:29 +0300 Subject: [PATCH 5/8] Implement set debug --- Sources/Qonversion.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/Qonversion.m b/Sources/Qonversion.m index 4c85a71c..c1a06f71 100644 --- a/Sources/Qonversion.m +++ b/Sources/Qonversion.m @@ -21,6 +21,7 @@ @implementation Qonversion static NSString* apiKey; static BOOL autoTrackPurchases; +static BOOL debugMode = NO; // MARK: - Public @@ -198,6 +199,8 @@ + (NSURLRequest *)makePostRequestWithEndpoint:(NSString *)endpoint andBody:(NSDi NSMutableDictionary *mutableBody = body.mutableCopy; + [mutableBody setObject:[[NSNumber alloc] initWithBool:debugMode] forKey:@"debug_mode"]; + [mutableBody setObject:apiKey forKey:@"access_token"]; [mutableBody setObject:kSDKVersion forKey:@"v"]; if (Keeper.userID && Keeper.userID.length > 2) { @@ -301,7 +304,7 @@ + (NSURLSession *)session { } + (void)setDebugMode:(BOOL) debugMode { - + debugMode = debugMode; } @end From eb8d6e1166b15ab6fadafc0323fe34532fd946be Mon Sep 17 00:00:00 2001 From: Sam Mejlumyan Date: Mon, 20 Apr 2020 15:49:37 +0300 Subject: [PATCH 6/8] Add qonversion tests --- Qonversion.xcodeproj/project.pbxproj | 4 ++++ QonversionTests/QonversionTests.m | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 QonversionTests/QonversionTests.m diff --git a/Qonversion.xcodeproj/project.pbxproj b/Qonversion.xcodeproj/project.pbxproj index d48d8552..b7161ac7 100644 --- a/Qonversion.xcodeproj/project.pbxproj +++ b/Qonversion.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 45202189244DD02F00C1A928 /* QonversionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 45202188244DD02F00C1A928 /* QonversionTests.m */; }; 459DAB73243E329F0011ECF3 /* Qonversion.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 459DAB69243E329F0011ECF3 /* Qonversion.framework */; }; 459DAB9A243E333C0011ECF3 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 459DAB97243E333C0011ECF3 /* README.md */; }; 459DAB9B243E333C0011ECF3 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 459DAB98243E333C0011ECF3 /* LICENSE */; }; @@ -52,6 +53,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 45202188244DD02F00C1A928 /* QonversionTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QonversionTests.m; sourceTree = ""; }; 459DAB69243E329F0011ECF3 /* Qonversion.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Qonversion.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 459DAB72243E329F0011ECF3 /* QonversionTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = QonversionTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 459DAB79243E329F0011ECF3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -151,6 +153,7 @@ 459DAC0A243E4D420011ECF3 /* Helpers */, 459DAC07243E4AF20011ECF3 /* Resources */, 459DAC05243E49C20011ECF3 /* QonversionMapperTests.m */, + 45202188244DD02F00C1A928 /* QonversionTests.m */, 459DAB79243E329F0011ECF3 /* Info.plist */, ); path = QonversionTests; @@ -444,6 +447,7 @@ buildActionMask = 2147483647; files = ( 459DAC0D243E4D610011ECF3 /* XCTestCase+TestJSON.m in Sources */, + 45202189244DD02F00C1A928 /* QonversionTests.m in Sources */, 459DAC06243E49C20011ECF3 /* QonversionMapperTests.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/QonversionTests/QonversionTests.m b/QonversionTests/QonversionTests.m new file mode 100644 index 00000000..31ecfd2b --- /dev/null +++ b/QonversionTests/QonversionTests.m @@ -0,0 +1,27 @@ +#import +#import "Qonversion.h" + +@interface Qonversion (Tests) ++ (NSURLRequest *)makePostRequestWithEndpoint:(NSString *)endpoint andBody:(NSDictionary *)body; +@end + +@interface QonversionTests : XCTestCase + +@end + +@implementation QonversionTests + +- (void)testThatDebugModeSetCorrectly { + [Qonversion setDebugMode:YES]; + [Qonversion launchWithKey:@"key" userID:@"user"]; + NSURLRequest *request = [Qonversion makePostRequestWithEndpoint:@"dummy" andBody:@{}]; + XCTAssertNotNil(request); + + NSError* error; + NSDictionary* json = [NSJSONSerialization JSONObjectWithData:request.HTTPBody + options:kNilOptions + error:&error]; + +} + +@end From a9ed2ce292da0e443bf0b8358c06108503c124c4 Mon Sep 17 00:00:00 2001 From: Sam Mejlumyan Date: Mon, 20 Apr 2020 16:01:47 +0300 Subject: [PATCH 7/8] Add test for debug mode --- QonversionTests/Helpers/XCTestCase+TestJSON.h | 1 + QonversionTests/QonversionTests.m | 28 +++++++++++++++---- Sources/Qonversion.m | 6 ++-- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/QonversionTests/Helpers/XCTestCase+TestJSON.h b/QonversionTests/Helpers/XCTestCase+TestJSON.h index db56d953..5396ae17 100644 --- a/QonversionTests/Helpers/XCTestCase+TestJSON.h +++ b/QonversionTests/Helpers/XCTestCase+TestJSON.h @@ -4,5 +4,6 @@ - (id)JSONObjectFromContentsOfFile:(NSString *)filePath; - (id)fileDataFromContentsOfFile:(NSString *)filePath; +- (id)JSONObjectFromData:(NSData *)data; @end diff --git a/QonversionTests/QonversionTests.m b/QonversionTests/QonversionTests.m index 31ecfd2b..77fa8ade 100644 --- a/QonversionTests/QonversionTests.m +++ b/QonversionTests/QonversionTests.m @@ -1,5 +1,6 @@ #import #import "Qonversion.h" +#import "XCTestCase+TestJSON.h" @interface Qonversion (Tests) + (NSURLRequest *)makePostRequestWithEndpoint:(NSString *)endpoint andBody:(NSDictionary *)body; @@ -11,17 +12,34 @@ @interface QonversionTests : XCTestCase @implementation QonversionTests +- (void)setUp { + [super setUp]; + + // Set default value before + [Qonversion setDebugMode:NO]; +} + +- (void)testThatDebugModeSetDefaultValueAsNoCorrectly { + [Qonversion launchWithKey:@"key" userID:@"user"]; + NSURLRequest *request = [Qonversion makePostRequestWithEndpoint:@"dummy" andBody:@{}]; + XCTAssertNotNil(request); + NSDictionary *body = [self JSONObjectFromData:request.HTTPBody]; + XCTAssertNotNil(body); + + NSNumber *debugMode = body[@"debug_mode"]; + XCTAssertEqual(debugMode.copy, @NO); +} + - (void)testThatDebugModeSetCorrectly { [Qonversion setDebugMode:YES]; [Qonversion launchWithKey:@"key" userID:@"user"]; NSURLRequest *request = [Qonversion makePostRequestWithEndpoint:@"dummy" andBody:@{}]; XCTAssertNotNil(request); + NSDictionary *body = [self JSONObjectFromData:request.HTTPBody]; + XCTAssertNotNil(body); - NSError* error; - NSDictionary* json = [NSJSONSerialization JSONObjectWithData:request.HTTPBody - options:kNilOptions - error:&error]; - + NSNumber *debugMode = body[@"debug_mode"]; + XCTAssertEqual(debugMode, @YES); } @end diff --git a/Sources/Qonversion.m b/Sources/Qonversion.m index c1a06f71..507b62c7 100644 --- a/Sources/Qonversion.m +++ b/Sources/Qonversion.m @@ -21,7 +21,7 @@ @implementation Qonversion static NSString* apiKey; static BOOL autoTrackPurchases; -static BOOL debugMode = NO; +static BOOL _debugMode = NO; // MARK: - Public @@ -199,7 +199,7 @@ + (NSURLRequest *)makePostRequestWithEndpoint:(NSString *)endpoint andBody:(NSDi NSMutableDictionary *mutableBody = body.mutableCopy; - [mutableBody setObject:[[NSNumber alloc] initWithBool:debugMode] forKey:@"debug_mode"]; + [mutableBody setObject:[[NSNumber alloc] initWithBool:_debugMode] forKey:@"debug_mode"]; [mutableBody setObject:apiKey forKey:@"access_token"]; [mutableBody setObject:kSDKVersion forKey:@"v"]; @@ -304,7 +304,7 @@ + (NSURLSession *)session { } + (void)setDebugMode:(BOOL) debugMode { - debugMode = debugMode; + _debugMode = debugMode; } @end From adb81e571c500aa4ac1d7440010aff07c448387b Mon Sep 17 00:00:00 2001 From: Sam Mejlumyan Date: Mon, 20 Apr 2020 16:02:50 +0300 Subject: [PATCH 8/8] Bump version --- Qonversion.podspec | 2 +- Sources/Qonversion.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Qonversion.podspec b/Qonversion.podspec index 471294ce..16911d0f 100644 --- a/Qonversion.podspec +++ b/Qonversion.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Qonversion' - s.version = '1.0.0-beta.3' + s.version = '1.0.0-beta.4' s.summary = 'qonversion.io' s.description = <<-DESC Deep Analytics for iOS Subscriptions diff --git a/Sources/Qonversion.m b/Sources/Qonversion.m index 507b62c7..12bdd884 100644 --- a/Sources/Qonversion.m +++ b/Sources/Qonversion.m @@ -3,7 +3,7 @@ #import "UserInfo.h" #import "QonversionMapper.h" -static NSString * const kBaseURL = @"https://apib.qonversion.io/"; +static NSString * const kBaseURL = @"https://api.qonversion.io/"; static NSString * const kInitEndpoint = @"init"; static NSString * const kPurchaseEndpoint = @"purchase"; static NSString * const kCheckEndpoint = @"check";