Skip to content

Commit

Permalink
Merge pull request #821 from Microsoft/fix/run-crash-confirmation-in-ui
Browse files Browse the repository at this point in the history
Run user confirmation handler from main thread
  • Loading branch information
iamclement authored Oct 26, 2017
2 parents 3ba4047 + 8b59ea3 commit edab581
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
28 changes: 18 additions & 10 deletions MobileCenterCrashes/MobileCenterCrashes.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,11 @@
04CC3B811F35284D00F7D92A /* MSWrapperExceptionInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 353FD1601F29209000E1DF78 /* MSWrapperExceptionInternal.h */; };
04CC3B821F35284E00F7D92A /* MSWrapperExceptionInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 353FD1601F29209000E1DF78 /* MSWrapperExceptionInternal.h */; };
04CC3B831F3528BD00F7D92A /* MSWrapperCrashesHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 350B29E81F1929A1009B91CF /* MSWrapperCrashesHelper.h */; settings = {ATTRIBUTES = (Public, ); }; };
04CC3B841F3528BE00F7D92A /* MSWrapperCrashesHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 350B29E81F1929A1009B91CF /* MSWrapperCrashesHelper.h */; };
04CC3B851F3528BF00F7D92A /* MSWrapperCrashesHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 350B29E81F1929A1009B91CF /* MSWrapperCrashesHelper.h */; };
04CC3B841F3528BE00F7D92A /* MSWrapperCrashesHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 350B29E81F1929A1009B91CF /* MSWrapperCrashesHelper.h */; settings = {ATTRIBUTES = (Public, ); }; };
04CC3B851F3528BF00F7D92A /* MSWrapperCrashesHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 350B29E81F1929A1009B91CF /* MSWrapperCrashesHelper.h */; settings = {ATTRIBUTES = (Public, ); }; };
04CC3B861F3528C200F7D92A /* MSCrashHandlerSetupDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 350B29E71F192554009B91CF /* MSCrashHandlerSetupDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
04CC3B871F3528C300F7D92A /* MSCrashHandlerSetupDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 350B29E71F192554009B91CF /* MSCrashHandlerSetupDelegate.h */; };
04CC3B881F3528C400F7D92A /* MSCrashHandlerSetupDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 350B29E71F192554009B91CF /* MSCrashHandlerSetupDelegate.h */; };
04CC3B871F3528C300F7D92A /* MSCrashHandlerSetupDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 350B29E71F192554009B91CF /* MSCrashHandlerSetupDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
04CC3B881F3528C400F7D92A /* MSCrashHandlerSetupDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 350B29E71F192554009B91CF /* MSCrashHandlerSetupDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
04CC3B891F3528DA00F7D92A /* MSWrapperExceptionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 350B29F31F1E6F1D009B91CF /* MSWrapperExceptionTests.m */; };
04CC3B8A1F3528E200F7D92A /* MSWrapperCrashesHelperTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 352B1D6E1F27C36300684A7F /* MSWrapperCrashesHelperTests.m */; };
04EBBEB21F01C0C90006B8AE /* MSErrorReport.m in Sources */ = {isa = PBXBuildFile; fileRef = B2F120DF1D657CF10060DED7 /* MSErrorReport.m */; };
Expand Down Expand Up @@ -839,17 +839,24 @@
name = iOS;
sourceTree = "<group>";
};
350B29E91F192A5C009B91CF /* WrapperSdkUtilities */ = {
350B29E91F192A5C009B91CF /* WrapperSDKUtilities */ = {
isa = PBXGroup;
children = (
350B29E81F1929A1009B91CF /* MSWrapperCrashesHelper.h */,
350B29F11F1D67EE009B91CF /* MSWrapperCrashesHelper.m */,
350B29E71F192554009B91CF /* MSCrashHandlerSetupDelegate.h */,
35B7D8791DE4CB6D00C846CD /* MSWrapperExceptionManagerInternal.h */,
35D504CE1DDD140500D58B40 /* MSWrapperExceptionManager.m */,
35D504CD1DDD140500D58B40 /* MSWrapperExceptionManager.h */,
);
name = WrapperSdkUtilities;
name = WrapperSDKUtilities;
sourceTree = "<group>";
};
380609CC1FA2848D00211C22 /* WrapperSDKUtilities */ = {
isa = PBXGroup;
children = (
350B29E71F192554009B91CF /* MSCrashHandlerSetupDelegate.h */,
350B29E81F1929A1009B91CF /* MSWrapperCrashesHelper.h */,
350B29F11F1D67EE009B91CF /* MSWrapperCrashesHelper.m */,
);
path = WrapperSDKUtilities;
sourceTree = "<group>";
};
6E04012A1D1C98690051BCFA = {
Expand Down Expand Up @@ -888,6 +895,7 @@
6E0401501D1C9A4F0051BCFA /* MSCrashes.mm */,
B2DCB1351DAC03C400120F87 /* MSCrashesDelegate.h */,
B2F120DE1D657CF10060DED7 /* MSErrorReport.h */,
380609CC1FA2848D00211C22 /* WrapperSDKUtilities */,
6E0401511D1C9A4F0051BCFA /* Internals */,
D38024001E7125F500466558 /* Model */,
6E37297E1D1DE93800F1E4AE /* Support */,
Expand All @@ -898,7 +906,7 @@
6E0401511D1C9A4F0051BCFA /* Internals */ = {
isa = PBXGroup;
children = (
350B29E91F192A5C009B91CF /* WrapperSdkUtilities */,
350B29E91F192A5C009B91CF /* WrapperSDKUtilities */,
3515F9C01DD63EC9005E6E27 /* MSCrashesInternal.h */,
6E73FE711D4059E7008CDC15 /* MSCrashesCXXExceptionWrapperException.h */,
6E73FE721D4059E7008CDC15 /* MSCrashesCXXExceptionWrapperException.m */,
Expand Down
16 changes: 15 additions & 1 deletion MobileCenterCrashes/MobileCenterCrashes/MSCrashes.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ - (BOOL)sendCrashReportsOrAwaitUserConfirmation {
@"The flag for user confirmation is set to MSUserConfirmationAlways, continue sending logs");
[self notifyWithUserConfirmation:MSUserConfirmationSend];
return alwaysSend;
} else if (self.automaticProcessing && !(self.userConfirmationHandler && self.userConfirmationHandler(self.unprocessedReports))) {
} else if (self.automaticProcessing && !(self.userConfirmationHandler && [self userPromptedForConfirmation])) {

// User confirmation handler doesn't exist or returned NO which means 'want to process'.
MSLogDebug([MSCrashes logTag],
Expand All @@ -1086,6 +1086,20 @@ - (BOOL)sendCrashReportsOrAwaitUserConfirmation {
return alwaysSend;
}

-(BOOL)userPromptedForConfirmation{

// User confirmation handler may contain UI so we have to run it in the main thread.
__block BOOL userPromptedForConfirmation;
if ([NSThread isMainThread]) {
userPromptedForConfirmation = self.userConfirmationHandler(self.unprocessedReports);
} else {
dispatch_sync(dispatch_get_main_queue(), ^{
userPromptedForConfirmation = self.userConfirmationHandler(self.unprocessedReports);
});
}
return userPromptedForConfirmation;
}

// This is an instance method to make testing easier.
- (BOOL)shouldAlwaysSend {
NSNumber *flag = [MS_USER_DEFAULTS objectForKey:kMSUserConfirmationKey];
Expand Down
3 changes: 3 additions & 0 deletions MobileCenterCrashes/MobileCenterCrashes/MobileCenterCrashes.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@

#import "MSCrashes.h"
#import "MSCrashesDelegate.h"
#import "MSCrashHandlerSetupDelegate.h"
#import "MSErrorAttachmentLog.h"
#import "MSErrorAttachmentLog+Utility.h"
#import "MSWrapperCrashesHelper.h"

0 comments on commit edab581

Please sign in to comment.