Skip to content

Commit

Permalink
Launch deeplink from main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
nonelse committed Mar 11, 2016
1 parent 1ec7d6d commit 111b835
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 35 deletions.
73 changes: 39 additions & 34 deletions Adjust/ADJActivityHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,7 @@ - (void)launchAttributionResponseTasks:(ADJAttributionResponseData *)attribution
});
}

- (void)launchDeepLink:(NSDictionary *)jsonDict{
if ([ADJUtil isNull:jsonDict]) return;

NSString *deepLink = [jsonDict objectForKey:@"deeplink"];
- (void)launchDeepLink:(NSString *)deepLink{
if (deepLink == nil) return;

NSURL* deepLinkUrl = [NSURL URLWithString:deepLink];
Expand Down Expand Up @@ -512,37 +509,45 @@ - (void) launchEventResponseTasksInternal:(ADJEventResponseData *)eventResponseD
- (void) launchSessionResponseTasksInternal:(ADJSessionResponseData *)sessionResponseData {
BOOL toLaunchAttributionDelegate = [self updateAttribution:sessionResponseData.attribution];

// Send tasks to background to avoid blocking the activity handler queue
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// session success callback
if (sessionResponseData.success
&& [self.adjustDelegate respondsToSelector:@selector(adjustSessionTrackingSucceeded:)])
{
[self.logger debug:@"Launching success session tracking delegate"];
[self.adjustDelegate performSelectorOnMainThread:@selector(adjustSessionTrackingSucceeded:)
withObject:[sessionResponseData successResponseData]
waitUntilDone:YES]; // blocking
}
// session failure callback
if (!sessionResponseData.success
&& [self.adjustDelegate respondsToSelector:@selector(adjustSessionTrackingFailed:)])
{
[self.logger debug:@"Launching failed session tracking delegate"];
[self.adjustDelegate performSelectorOnMainThread:@selector(adjustSessionTrackingFailed:)
withObject:[sessionResponseData failureResponseData]
waitUntilDone:NO]; // blocking
}
// session success callback
if (sessionResponseData.success
&& [self.adjustDelegate respondsToSelector:@selector(adjustSessionTrackingSucceeded:)])
{
[self.logger debug:@"Launching success session tracking delegate"];
[self.adjustDelegate performSelectorOnMainThread:@selector(adjustSessionTrackingSucceeded:)
withObject:[sessionResponseData successResponseData]
waitUntilDone:NO]; // non-blocking
}
// session failure callback
if (!sessionResponseData.success
&& [self.adjustDelegate respondsToSelector:@selector(adjustSessionTrackingFailed:)])
{
[self.logger debug:@"Launching failed session tracking delegate"];
[self.adjustDelegate performSelectorOnMainThread:@selector(adjustSessionTrackingFailed:)
withObject:[sessionResponseData failureResponseData]
waitUntilDone:NO]; // non-blocking
}

// try to update and launch the attribution changed delegate blocking
if (toLaunchAttributionDelegate) {
[self.logger debug:@"Launching attribution changed delegate"];
[self.adjustDelegate performSelectorOnMainThread:@selector(adjustAttributionChanged:)
withObject:sessionResponseData.attribution
waitUntilDone:YES]; // blocking
}
// try to launch the deeplink after attribution changed delegate
[self launchDeepLink:sessionResponseData.jsonResponse];
});
// try to update and launch the attribution changed delegate blocking
if (toLaunchAttributionDelegate) {
[self.logger debug:@"Launching attribution changed delegate"];
[self.adjustDelegate performSelectorOnMainThread:@selector(adjustAttributionChanged:)
withObject:sessionResponseData.attribution
waitUntilDone:NO]; // non-blocking
}

if ([ADJUtil isNull:sessionResponseData.jsonResponse]) {
return;
}

NSString *deepLink = [sessionResponseData.jsonResponse objectForKey:@"deeplink"];
if (deepLink == nil) {
return;
}

[self performSelectorOnMainThread:@selector(launchDeepLink:)
withObject:deepLink
waitUntilDone:NO]; // non-blocking
}

- (void) launchAttributionResponseTasksInternal:(ADJAttributionResponseData *)attributionResponseData {
Expand Down
2 changes: 1 addition & 1 deletion Adjust/ADJConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* Optional delegate that will get informed about tracking results
*/
@protocol AdjustDelegate
@protocol AdjustDelegate
@optional

/**
Expand Down

0 comments on commit 111b835

Please sign in to comment.