diff --git a/Adjust.podspec b/Adjust.podspec index 70a30868c..e6f4ab7c2 100644 --- a/Adjust.podspec +++ b/Adjust.podspec @@ -1,11 +1,11 @@ Pod::Spec.new do |s| s.name = "Adjust" - s.version = "4.0.5" + s.version = "4.0.6" s.summary = "This is the iOS SDK of adjust. You can read more about it at http://adjust.com." s.homepage = "http://adjust.com" s.license = { :type => 'MIT', :file => 'MIT-LICENSE' } s.author = { "Christian Wellenbrock" => "welle@adjust.com" } - s.source = { :git => "https://github.com/adjust/ios_sdk.git", :tag => "v4.0.5" } + s.source = { :git => "https://github.com/adjust/ios_sdk.git", :tag => "v4.0.6" } s.platform = :ios, '4.3' s.framework = 'SystemConfiguration' s.weak_framework = 'AdSupport', 'iAd' diff --git a/Adjust/ADJActivityHandler.m b/Adjust/ADJActivityHandler.m index 9730d8ed8..70f3e2551 100644 --- a/Adjust/ADJActivityHandler.m +++ b/Adjust/ADJActivityHandler.m @@ -106,7 +106,7 @@ - (void)trackEvent:(ADJEvent *)event - (void)finishedTrackingWithResponse:(NSDictionary *)jsonDict{ [self launchDeepLink:jsonDict]; - [self.attributionHandler checkAttribution:jsonDict]; + [[self getAttributionHandler] checkAttribution:jsonDict]; } - (void)launchDeepLink:(NSDictionary *)jsonDict{ @@ -205,15 +205,14 @@ - (void)launchAttributionDelegate{ } - (void)setOfflineMode:(BOOL)isOffline { + self.offline = isOffline; if (isOffline) { - self.offline = YES; - [self endInternal]; [self.logger info:@"Pausing package handler to put in offline mode"]; + [self endInternal]; } else { - self.offline = NO; + [self.logger info:@"Resuming package handler to put in online mode"]; [self.packageHandler resumeSending]; [self startTimer]; - [self.logger info:@"Resuming package handler to put in online mode"]; } } @@ -240,30 +239,31 @@ - (void)initInternal { [self.logger info:@"Event buffering is enabled"]; } - [[UIDevice currentDevice] adjSetIad:self]; - [self readAttribution]; [self readActivityState]; self.packageHandler = [ADJAdjustFactory packageHandlerForActivityHandler:self]; - self.attributionHandler = [self buildAttributionHandler]; - self.shouldGetAttribution = YES; + [[UIDevice currentDevice] adjSetIad:self]; + [self startInternal]; } -- (id) buildAttributionHandler { - ADJPackageBuilder *attributionBuilder = [[ADJPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo - activityState:self.activityState - config:self.adjustConfig]; - ADJActivityPackage *attributionPackage = [attributionBuilder buildAttributionPackage]; - id attributionHandler = [ADJAdjustFactory attributionHandlerForActivityHandler:self - withMaxDelay:nil - withAttributionPackage:attributionPackage]; +- (id) getAttributionHandler { + //TODO self.activity state can be null in the first session + if (self.attributionHandler == nil) { + ADJPackageBuilder *attributionBuilder = [[ADJPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo + activityState:self.activityState + config:self.adjustConfig]; + ADJActivityPackage *attributionPackage = [attributionBuilder buildAttributionPackage]; + self.attributionHandler = [ADJAdjustFactory attributionHandlerForActivityHandler:self + withMaxDelay:nil + withAttributionPackage:attributionPackage]; + } - return attributionHandler; + return self.attributionHandler; } - (void)startInternal { @@ -325,7 +325,7 @@ - (void)startInternal { if (self.attribution == nil || self.activityState.askingAttribution) { if (self.shouldGetAttribution) { - [self.attributionHandler getAttribution]; + [[self getAttributionHandler] getAttribution]; } } } @@ -373,65 +373,81 @@ - (void)eventInternal:(ADJEvent *)event - (void) appWillOpenUrlInternal:(NSURL *)url { NSArray* queryArray = [url.query componentsSeparatedByString:@"&"]; + if (queryArray == nil) { + return; + } + NSMutableDictionary* adjustDeepLinks = [NSMutableDictionary dictionary]; - ADJAttribution *attribution = [[ADJAttribution alloc] init]; + ADJAttribution *deeplinkAttribution = [[ADJAttribution alloc] init]; + BOOL hasDeepLink = NO; for (NSString* fieldValuePair in queryArray) { - NSArray* pairComponents = [fieldValuePair componentsSeparatedByString:@"="]; - if (pairComponents.count != 2) continue; - - NSString* key = [pairComponents objectAtIndex:0]; - if (![key hasPrefix:kAdjustPrefix]) continue; - - NSString* value = [pairComponents objectAtIndex:1]; - if (value.length == 0) continue; - - NSString* keyWOutPrefix = [key substringFromIndex:kAdjustPrefix.length]; - if (keyWOutPrefix.length == 0) continue; - - if (![self trySetAttributionDeeplink:attribution withKey:keyWOutPrefix withValue:value]) { - [adjustDeepLinks setObject:value forKey:keyWOutPrefix]; + if([self readDeeplinkQueryString:fieldValuePair adjustDeepLinks:adjustDeepLinks attribution:deeplinkAttribution]) { + hasDeepLink = YES; } } - if ([adjustDeepLinks count] == 0) { + if (!hasDeepLink) { return; } - [self.attributionHandler getAttribution]; + [[self getAttributionHandler] getAttribution]; ADJPackageBuilder *clickBuilder = [[ADJPackageBuilder alloc] initWithDeviceInfo:self.deviceInfo activityState:self.activityState config:self.adjustConfig]; clickBuilder.deeplinkParameters = adjustDeepLinks; - clickBuilder.attribution = attribution; + clickBuilder.attribution = deeplinkAttribution; [clickBuilder setClickTime:[NSDate date]]; ADJActivityPackage *clickPackage = [clickBuilder buildClickPackage:@"deeplink"]; [self.packageHandler sendClickPackage:clickPackage]; } -- (BOOL) trySetAttributionDeeplink:(ADJAttribution *)attribution +- (BOOL) readDeeplinkQueryString:(NSString *)queryString + adjustDeepLinks:(NSMutableDictionary*)adjustDeepLinks + attribution:(ADJAttribution *)deeplinkAttribution +{ + NSArray* pairComponents = [queryString componentsSeparatedByString:@"="]; + if (pairComponents.count != 2) return NO; + + NSString* key = [pairComponents objectAtIndex:0]; + if (![key hasPrefix:kAdjustPrefix]) return NO; + + NSString* value = [pairComponents objectAtIndex:1]; + if (value.length == 0) return NO; + + NSString* keyWOutPrefix = [key substringFromIndex:kAdjustPrefix.length]; + if (keyWOutPrefix.length == 0) return NO; + + if (![self trySetAttributionDeeplink:deeplinkAttribution withKey:keyWOutPrefix withValue:value]) { + [adjustDeepLinks setObject:value forKey:keyWOutPrefix]; + } + + return YES; +} + +- (BOOL) trySetAttributionDeeplink:(ADJAttribution *)deeplinkAttribution withKey:(NSString *)key withValue:(NSString*)value { if ([key isEqualToString:@"tracker"]) { - attribution.trackerName = value; + deeplinkAttribution.trackerName = value; return YES; } if ([key isEqualToString:@"campaign"]) { - attribution.campaign = value; + deeplinkAttribution.campaign = value; return YES; } if ([key isEqualToString:@"adgroup"]) { - attribution.adgroup = value; + deeplinkAttribution.adgroup = value; return YES; } if ([key isEqualToString:@"creative"]) { - attribution.creative = value; + deeplinkAttribution.creative = value; return YES; } diff --git a/Adjust/ADJPackageBuilder.m b/Adjust/ADJPackageBuilder.m index a2629d55e..358598d83 100644 --- a/Adjust/ADJPackageBuilder.m +++ b/Adjust/ADJPackageBuilder.m @@ -93,7 +93,7 @@ - (ADJActivityPackage *)buildAttributionPackage { [self parameters:parameters setString:self.adjustConfig.appToken forKey:@"app_token"]; [self parameters:parameters setString:self.adjustConfig.environment forKey:@"environment"]; [self parameters:parameters setString:self.activityState.uuid forKey:@"ios_uuid"]; - [self parameters:parameters setBool:self.adjustConfig.hasDelegate forKey:@"needs_attribution_data"]; + [self parameters:parameters setBool:self.adjustConfig.hasDelegate forKey:@"needs_attribution_data"]; ADJActivityPackage *attributionPackage = [self defaultActivityPackage]; attributionPackage.path = @"/attribution"; diff --git a/Adjust/ADJUtil.m b/Adjust/ADJUtil.m index c7bb1472f..fd62fa402 100644 --- a/Adjust/ADJUtil.m +++ b/Adjust/ADJUtil.m @@ -16,7 +16,7 @@ #include static NSString * const kBaseUrl = @"https://app.adjust.com"; -static NSString * const kClientSdk = @"ios4.0.5"; +static NSString * const kClientSdk = @"ios4.0.6"; static NSString * const kDateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'Z"; static NSDateFormatter *dateFormat; diff --git a/AdjustTests/ADJActivityHandlerTests.m b/AdjustTests/ADJActivityHandlerTests.m index e316340f5..aea491bfa 100644 --- a/AdjustTests/ADJActivityHandlerTests.m +++ b/AdjustTests/ADJActivityHandlerTests.m @@ -106,8 +106,6 @@ - (void)testFirstRun // Handler initializations XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJPackageHandler initWithActivityHandler"], @"%@", self.loggerMock); - XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJAttributionHandlerMock initWithActivityHandler"], - @"%@", self.loggerMock); // when a session package is being sent the package handler should resume sending XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJPackageHandler resumeSending"], @@ -123,7 +121,7 @@ - (void)testFirstRun ADJActivityPackage *activityPackage = (ADJActivityPackage *) self.packageHandlerMock.packageQueue[0]; // check the Sdk version is being tested - XCTAssertEqual(@"ios4.0.5", activityPackage.clientSdk, @"%@", activityPackage.extendedString); + XCTAssertEqual(@"ios4.0.6", activityPackage.clientSdk, @"%@", activityPackage.extendedString); // check the server url XCTAssertEqual(@"https://app.adjust.com", ADJUtil.baseUrl); @@ -210,6 +208,8 @@ - (void)testFirstRun @"%@", self.loggerMock); // check that the package handler calls back with the json dict response + XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJAttributionHandlerMock initWithActivityHandler"], + @"%@", self.loggerMock); XCTAssert([self.loggerMock containsMessage:ADJLogLevelTest beginsWith:@"ADJAttributionHandlerMock checkAttribution"], @"%@", self.loggerMock); diff --git a/VERSION b/VERSION index 7636e7565..d13e837c8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.0.5 +4.0.6 diff --git a/doc/migrate.md b/doc/migrate.md index cc53d2343..3002a448d 100644 --- a/doc/migrate.md +++ b/doc/migrate.md @@ -1,4 +1,4 @@ -## Migrate your adjust SDK for iOS to v4.0.5 from v3.4.0 +## Migrate your adjust SDK for iOS to v4.0.6 from v3.4.0 ### Initial setup diff --git a/example/example/AppDelegate.m b/example/example/AppDelegate.m index d81a10a98..33af4be49 100644 --- a/example/example/AppDelegate.m +++ b/example/example/AppDelegate.m @@ -46,6 +46,13 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( return YES; } +- (BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation +{ + [Adjust appWillOpenUrl:url]; + + return YES; +} + - (void)adjustAttributionChanged:(ADJAttribution *)attribution { NSLog(@"adjust attribution %@", attribution); } diff --git a/example/example/Info.plist b/example/example/Info.plist index c6d8e00cf..3bf10cbff 100644 --- a/example/example/Info.plist +++ b/example/example/Info.plist @@ -4,6 +4,17 @@ CFBundleDevelopmentRegion en + CFBundleURLTypes + + + CFBundleURLSchemes + + adjustExample + + CFBundleURLName + com.adjust.example + + CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier