UIAlertController crashes (SIGABRT) when adding second action
Asked Answered
J

1

5

I see a very strange behavior in one of my apps since a few days. A UIAlertController crashes as soon as I add a second action. Here is the code>

let alertController = UIAlertController.init(title: title, message: message, preferredStyle: .Alert)

for  action in actions
{
    alertController.addAction(action)
}

actions is an array containing UIAlertAction elements, in my case 2. I already tried reordering the actions to see if there was a problem with a specific UIAlertAction object, but no, the app always crashes when adding the second action. I create them like this:

let cancelAction = UIAlertAction.init(title: "Cancel", style: .Cancel)
{ (action:UIAlertAction!) -> Void in
    print("User cancelled action");
}

Edit: here is how I create the array:

showAlertView("Proceed", message: proceedMessage, actions: [cancelAction, proceedAction])

Edit end

Most of this code comes from the Apple tutorials with little changes. The debugger is immediately jumping to the class AppDelegate: ... line with no other information then SIGABRT and in the crash logs I see this:

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Triggered by Thread:  0

Filtered syslog:
None found

Last Exception Backtrace:
0   CoreFoundation                  0x1832c6db0 __exceptionPreprocess + 124
1   libobjc.A.dylib                 0x18292bf80 objc_exception_throw + 56
2   CoreFoundation                  0x1832c6c80 +[NSException raise:format:arguments:] + 108
3   Foundation                      0x183c4c154 -[NSAssertionHandler   handleFailureInMethod:object:file:lineNumber:description:] + 112
4   UIKit                           0x188897c24 -[UIAlertController addAction:] + 220
5   MyApp                           0x10007bb60 0x10006c000 + 64352
6   MyApp                           0x10007b648 0x10006c000 + 63048
7   MyApp                           0x10007929c 0x10006c000 + 53916
8   MyApp                           0x100079554 0x10006c000 + 54612
9   UIKit                           0x1886de1a8 -[UIApplication _handleNonLaunchSpecificActions:forScene:withTransitionContext:completion:] + 2676
10  UIKit                           0x1886cbf84 -[UIApplication workspace:didReceiveActions:] + 136
11  FrontBoardServices              0x184c677ac __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36
12  FrontBoardServices              0x184c67618 -[FBSSerialQueue _performNext] + 168
13  FrontBoardServices              0x184c679c8 -[FBSSerialQueue _performNextFromRunLoopSource] + 56
14  CoreFoundation                  0x18327d09c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
15  CoreFoundation                  0x18327cb30 __CFRunLoopDoSources0 + 540
16  CoreFoundation                  0x18327a830 __CFRunLoopRun + 724
17  CoreFoundation                  0x1831a4c50 CFRunLoopRunSpecific + 384
18  GraphicsServices                0x184a8c088 GSEventRunModal + 180
19  UIKit                           0x18848e088 UIApplicationMain + 204
20  MyApp                           0x10007d984 0x10006c000 + 72068
21  libdyld.dylib                   0x182d428b8 start + 4

Does anybody have any idea? The strangest thing is, that the same code worked a couple of days ago. As I have a lot of problems with Xcode 7.3 after upgrading from Yosemite to El Capitan (basically it's almost unusable and constantly crashing) I re-installed it recently. But the code is the same...

Best regrads Bjoern

Julejulee answered 14/6, 2016 at 12:7 Comment(7)
Why you use for loop in actions?Anse
You should show how the actions array is created.Isolt
Have you tried running a clean before building? I've had situations where, for whatever reason, some piece of code hasn't been recompiled that should be after changing it and that causes these kinds of crash.Oxyhydrogen
Try adding a breakpoint on Objective-C exceptions in the Breakpoint Navigator. It might give a better description of the error in the debug console window.Drees
@Phillip Unfortunately, the Objective-C breakpoint reveals no further information. In fact the debugger stops three times at the line with .addAction, then it shows the SIGABRT. @Oxyhydrogen I did a Clean as well as uninstalling and re-installing the app. Nothing worked so far.Julejulee
@PhillipMills The last step before SIGABRT is 0x188897c24 <+220>: mov x0, x24Julejulee
@IyyappanRavi I use a function to dynamically create the UIAlertController, so I don't know how many actions there will be. But even if I call addAction() directly, without the loop, the app crashes on the second addAction call.Julejulee
A
11

My guess is that you set style: .Cancel on more than 1 action.

Aerotherapeutics answered 14/6, 2016 at 12:47 Comment(1)
Yes, this caused the problem. Is this documented somewhere?Julejulee

© 2022 - 2024 — McMap. All rights reserved.