From e8ce182273e8d93d154392f6139a134dd555c8fa Mon Sep 17 00:00:00 2001 From: Aleksandr Gusev Date: Sun, 29 Oct 2017 22:46:48 -0400 Subject: [PATCH] Fix potential deadlock when accessing a shared pasteboard from a background thread. --- Adjust/ADJAdditions/UIDevice+ADJAdditions.m | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Adjust/ADJAdditions/UIDevice+ADJAdditions.m b/Adjust/ADJAdditions/UIDevice+ADJAdditions.m index 2a566a242..c991d92ae 100644 --- a/Adjust/ADJAdditions/UIDevice+ADJAdditions.m +++ b/Adjust/ADJAdditions/UIDevice+ADJAdditions.m @@ -102,8 +102,16 @@ - (NSString *)adjFbAttributionId { #if ADJUST_NO_UIPASTEBOARD || TARGET_OS_TV return @""; #else - NSString *result = [UIPasteboard pasteboardWithName:@"fb_app_attribution" create:NO].string; - if (result == nil) return @""; + __block NSString *result; + void(^resultRetrievalBlock)(void) = ^{ + result = [UIPasteboard pasteboardWithName:@"fb_app_attribution" create:NO].string; + if (result == nil) { + result = @""; + } + }; + [NSThread isMainThread] ? + resultRetrievalBlock() : + dispatch_sync(dispatch_get_main_queue(), resultRetrievalBlock); return result; #endif }