Skip to content

Commit e48effd

Browse files
Fix crash related to nil completion handler.
Super simple bug, super simple fix. Fixes #269.
1 parent e2fbecc commit e48effd

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

Parse/Internal/PFAlertView.m

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ + (void)showAlertWithTitle:(NSString *)title
3131
message:message
3232
preferredStyle:UIAlertControllerStyleAlert];
3333

34-
void (^alertActionHandler)(UIAlertAction *) = [^(UIAlertAction *action){
35-
// This block intentionally retains alertController, and releases it afterwards.
36-
if (action.style == UIAlertActionStyleCancel) {
37-
completion(NSNotFound);
38-
} else {
39-
NSUInteger index = [alertController.actions indexOfObject:action];
40-
completion(index - 1);
34+
void (^alertActionHandler)(UIAlertAction *) = [^(UIAlertAction *action) {
35+
if (completion) {
36+
// This block intentionally retains alertController, and releases it afterwards.
37+
if (action.style == UIAlertActionStyleCancel) {
38+
completion(NSNotFound);
39+
} else {
40+
NSUInteger index = [alertController.actions indexOfObject:action];
41+
completion(index - 1);
42+
}
4143
}
4244
alertController = nil;
4345
} copy];
@@ -49,7 +51,7 @@ + (void)showAlertWithTitle:(NSString *)title
4951
for (NSString *buttonTitle in otherButtonTitles) {
5052
[alertController addAction:[UIAlertAction actionWithTitle:buttonTitle
5153
style:UIAlertActionStyleDefault
52-
handler:alertActionHandler]];
54+
handler:alertActionHandler]];
5355
}
5456

5557
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;

0 commit comments

Comments
 (0)