From bccfc61a4236df1811aebc2070bfc32d1a7432da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Spie=C3=9F?= Date: Mon, 5 Oct 2015 13:52:24 +0200 Subject: [PATCH] Add warnings to docs for threading, properly dispatch internally --- Classes/BITAuthenticator.h | 4 ++-- Classes/BITAuthenticator.m | 6 ++++-- Classes/BITFeedbackManager.h | 6 ++++++ Classes/BITFeedbackManager.m | 11 ++++++----- Classes/BITHockeyBaseManager.m | 2 -- Classes/BITUpdateManager.h | 2 ++ Classes/BITUpdateManager.m | 4 +++- 7 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Classes/BITAuthenticator.h b/Classes/BITAuthenticator.h index e740a2c9e2..df64cf3de6 100644 --- a/Classes/BITAuthenticator.h +++ b/Classes/BITAuthenticator.h @@ -313,7 +313,7 @@ typedef NS_ENUM(NSUInteger, BITAuthenticatorAppRestrictionEnforcementFrequency) * @see authenticateInstallation * @see validateWithCompletion: * - * @param completion Block being executed once identification completed + * @param completion Block being executed once identification completed. Be sure to properly dispatch code to the main queue if necessary. */ - (void) identifyWithCompletion:(void(^)(BOOL identified, NSError *error)) completion; @@ -342,7 +342,7 @@ typedef NS_ENUM(NSUInteger, BITAuthenticatorAppRestrictionEnforcementFrequency) * @see authenticateInstallation * @see identifyWithCompletion: * - * @param completion Block being executed once validation completed + * @param completion Block being executed once validation completed. Be sure to properly dispatch code to the main queue if necessary. */ - (void) validateWithCompletion:(void(^)(BOOL validated, NSError *error)) completion; diff --git a/Classes/BITAuthenticator.m b/Classes/BITAuthenticator.m index 68932a0c60..6beccedd16 100644 --- a/Classes/BITAuthenticator.m +++ b/Classes/BITAuthenticator.m @@ -169,7 +169,7 @@ static unsigned char kBITPNGEndChunk[4] = {0x49, 0x45, 0x4e, 0x44}; NSLog(@"[HockeySDK] ERROR: The authentication token could not be stored due to a keychain error. This is most likely a signing or keychain entitlement issue!"); } -- (void) identifyWithCompletion:(void (^)(BOOL identified, NSError *))completion { +- (void)identifyWithCompletion:(void (^)(BOOL identified, NSError *))completion { if(_authenticationController) { BITHockeyLog(@"Authentication controller already visible. Ignoring identify request"); if(completion) completion(NO, nil); @@ -246,7 +246,9 @@ static unsigned char kBITPNGEndChunk[4] = {0x49, 0x45, 0x4e, 0x44}; viewController.email = [self stringValueFromKeychainForKey:kBITAuthenticatorUserEmailKey]; _authenticationController = viewController; _identificationCompletion = completion; - [self showView:viewController]; + dispatch_async(dispatch_get_main_queue(), ^{ + [self showView:viewController]; + }); } #pragma mark - Validation diff --git a/Classes/BITFeedbackManager.h b/Classes/BITFeedbackManager.h index 100ef9399f..5c456e6b54 100644 --- a/Classes/BITFeedbackManager.h +++ b/Classes/BITFeedbackManager.h @@ -287,6 +287,8 @@ typedef NS_ENUM(NSInteger, BITFeedbackObservationMode) { /** Present the modal feedback list user interface. + + @warning This methods needs to be called on the main thread! */ - (void)showFeedbackListView; @@ -303,6 +305,8 @@ typedef NS_ENUM(NSInteger, BITFeedbackObservationMode) { /** Present the modal feedback compose message user interface. + + @warning This methods needs to be called on the main thread! */ - (void)showFeedbackComposeView; @@ -314,6 +318,7 @@ typedef NS_ENUM(NSInteger, BITFeedbackObservationMode) { @param items an NSArray with objects that should be attached @see `[BITFeedbackComposeViewController prepareWithItems:]` + @warning This methods needs to be called on the main thread! */ - (void)showFeedbackComposeViewWithPreparedItems:(NSArray *)items; @@ -325,6 +330,7 @@ typedef NS_ENUM(NSInteger, BITFeedbackObservationMode) { [[BITHockeyManager sharedHockeyManager].feedbackManager showFeedbackComposeViewWithGeneratedScreenshot]; @see feedbackObservationMode + @warning This methods needs to be called on the main thread! */ - (void)showFeedbackComposeViewWithGeneratedScreenshot; diff --git a/Classes/BITFeedbackManager.m b/Classes/BITFeedbackManager.m index b4e34fa474..c2c2b31497 100644 --- a/Classes/BITFeedbackManager.m +++ b/Classes/BITFeedbackManager.m @@ -220,8 +220,9 @@ NSString *const kBITFeedbackUpdateAttachmentThumbnail = @"BITFeedbackUpdateAttac BITHockeyLog(@"INFO: update view already visible, aborting"); return; } - - [self showView:[self feedbackListViewController:YES]]; + dispatch_async(dispatch_get_main_queue(), ^{ + [self showView:[self feedbackListViewController:YES]]; + }); } @@ -246,9 +247,9 @@ NSString *const kBITFeedbackUpdateAttachmentThumbnail = @"BITFeedbackUpdateAttac } BITFeedbackComposeViewController *composeView = [self feedbackComposeViewController]; [composeView prepareWithItems:items]; - - [self showView:composeView]; - + dispatch_async(dispatch_get_main_queue(), ^{ + [self showView:composeView]; + }); } - (void)showFeedbackComposeViewWithGeneratedScreenshot { diff --git a/Classes/BITHockeyBaseManager.m b/Classes/BITHockeyBaseManager.m index d2dd74aa66..dde6b76727 100644 --- a/Classes/BITHockeyBaseManager.m +++ b/Classes/BITHockeyBaseManager.m @@ -258,7 +258,6 @@ // if we compile Crash only, then BITHockeyBaseViewController is not included // in the headers and will cause a warning with the modulemap file #if HOCKEYSDK_FEATURE_AUTHENTICATOR || HOCKEYSDK_FEATURE_UPDATES || HOCKEYSDK_FEATURE_FEEDBACK - dispatch_async(dispatch_get_main_queue(), ^{ UIViewController *parentViewController = [self visibleWindowRootViewController]; // as per documentation this only works if called from within viewWillAppear: or viewDidAppear: @@ -295,7 +294,6 @@ [(BITHockeyBaseViewController *)viewController setModalAnimated:NO]; [visibleWindow addSubview:_navController.view]; } - }); #endif /* HOCKEYSDK_FEATURE_AUTHENTICATOR || HOCKEYSDK_FEATURE_UPDATES || HOCKEYSDK_FEATURE_FEEDBACK */ } #endif // HOCKEYSDK_CONFIGURATION_ReleaseCrashOnlyExtensions && HOCKEYSDK_CONFIGURATION_RelaseCrashOnlyWatchOS diff --git a/Classes/BITUpdateManager.h b/Classes/BITUpdateManager.h index a8a7b005b5..36747bd82c 100644 --- a/Classes/BITUpdateManager.h +++ b/Classes/BITUpdateManager.h @@ -220,6 +220,8 @@ typedef NS_ENUM (NSUInteger, BITUpdateSetting) { /** Present the modal update user interface. + + @warning Make sure to call this method from the main thread! */ - (void)showUpdateView; diff --git a/Classes/BITUpdateManager.m b/Classes/BITUpdateManager.m index 249d214d27..5425584fde 100644 --- a/Classes/BITUpdateManager.m +++ b/Classes/BITUpdateManager.m @@ -545,7 +545,9 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) { if ([self hasNewerMandatoryVersion] || [self expiryDateReached]) { [updateViewController setMandatoryUpdate: YES]; } - [self showView:updateViewController]; + dispatch_async(dispatch_get_main_queue(), ^{ + [self showView:updateViewController]; + }); }