I have received crash log from production and cannot understand how to reproduce it. It happened only once on iPad with iOS 9.3 as per information I have.
This crash happened after my latest release where I used VIPER methodology for some of my views. I have searched the Internet and suppose that my issue can be caused by similar issue like Leo Natan described in his comment here. But I am not sure and wondering how to reproduce and fix the issue. I do not even understand what popover is being presented.
Here is my crash log (removed binary images):
Incident Identifier: 9476D9A8-1468-4A68-8F71-DA8B7F083172
CrashReporter Key: 21204b1ae5f574c63137a73b5a4a50aeb35fe287
Hardware Model: iPad2,5
Process: CafeManager [24058]
Path: /private/var/containers/Bundle/Application/FF4319BD-9D3B-4178-B5FB-0B4641CB9D6E/CafeManager.app/CafeManager
Identifier: iGlock.CafeManager.com
Version: 1 (1.2.5)
Code Type: ARM (Native)
Parent Process: launchd [1]
Date/Time: 2018-08-27 03:16:59.59 +0300
Launch Time: 2018-08-27 03:04:59.59 +0300
OS Version: iOS 9.3.5 (13G36)
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x210df916 __exceptionPreprocess + 122 (NSException.m:162)
1 libobjc.A.dylib 0x2087ae12 objc_exception_throw + 34 (objc-exception.mm:531)
2 UIKit 0x25f4b480 -[UIPopoverPresentationController presentationTransitionWillBegin] + 3336 (UIPopoverPresentationController.m:1201)
3 UIKit 0x259abe8e __71-[UIPresentationController _initViewHierarchyForPresentationSuperview:]_block_invoke + 1794 (UIPresentationController.m:1137)
4 UIKit 0x259a9dae __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 378 (UIPresentationController.m:705)
5 UIKit 0x259034c4 _runAfterCACommitDeferredBlocks + 264 (UIApplication.m:2386)
6 UIKit 0x2590f7d6 _cleanUpAfterCAFlushAndRunDeferredBlocks + 86 (UIApplication.m:2365)
7 UIKit 0x2564db18 _afterCACommitHandler + 80 (UIApplication.m:2416)
8 CoreFoundation 0x210a16c4 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 16 (CFRunLoop.c:1620)
9 CoreFoundation 0x2109f9c8 __CFRunLoopDoObservers + 276 (CFRunLoop.c:1716)
10 CoreFoundation 0x2109fdfa __CFRunLoopRun + 954 (CFRunLoop.c:2558)
11 CoreFoundation 0x20fef224 CFRunLoopRunSpecific + 516 (CFRunLoop.c:2814)
12 CoreFoundation 0x20fef010 CFRunLoopRunInMode + 104 (CFRunLoop.c:2844)
13 GraphicsServices 0x225dfac4 GSEventRunModal + 156 (GSEvent.c:2245)
14 UIKit 0x256c3184 UIApplicationMain + 140 (UIApplication.m:3772)
15 CafeManager 0x9973c main + 48 (AppDelegate.swift:20)
16 libdyld.dylib 0x20c9786e tlv_get_addr + 42 (threadLocalHelpers.s:311)
Thread 0 name:
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x20d6ac5c __pthread_kill + 8
1 libsystem_pthread.dylib 0x20e14732 pthread_kill + 62 (pthread.c:1247)
2 libsystem_c.dylib 0x20cff0ac abort + 108 (abort.c:91)
3 libc++abi.dylib 0x20856ae4 abort_message + 108 (abort_message.cpp:47)
4 libc++abi.dylib 0x2086f69e default_terminate_handler() + 266 (cxa_default_handlers.cpp:67)
5 libobjc.A.dylib 0x2087b0b0 _objc_terminate() + 192 (objc-exception.mm:678)
6 libc++abi.dylib 0x2086ce16 std::__terminate(void (*)()) + 78 (cxa_handlers.cpp:67)
7 libc++abi.dylib 0x2086c8f8 __cxa_rethrow + 100 (cxa_exception.cpp:480)
8 libobjc.A.dylib 0x2087af5e objc_exception_rethrow + 42 (objc-exception.mm:581)
9 CoreFoundation 0x20fef2ae CFRunLoopRunSpecific + 654 (CFRunLoop.c:2827)
10 CoreFoundation 0x20fef014 CFRunLoopRunInMode + 108 (CFRunLoop.c:2844)
11 GraphicsServices 0x225dfac8 GSEventRunModal + 160 (GSEvent.c:2245)
12 UIKit 0x256c3188 UIApplicationMain + 144 (UIApplication.m:3772)
13 CafeManager 0x00099740 main + 52 (AppDelegate.swift:20)
14 libdyld.dylib 0x20c97872 start + 2 (start_glue.s:64)
Thread 1 name:
Thread 1:
0 libsystem_kernel.dylib 0x20d6c2f8 kevent_qos + 24
1 libdispatch.dylib 0x20c61d60 _dispatch_mgr_invoke + 256 (source.c:2542)
2 libdispatch.dylib 0x20c61abe _dispatch_mgr_thread$VARIANT$mp + 38 (source.c:2573)
Thread 2:
0 libsystem_kernel.dylib 0x20d6b864 __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x20e11b34 _pthread_wqthread + 1036 (pthread.c:1999)
2 libsystem_pthread.dylib 0x20e11718 start_wqthread + 8 (pthread_asm.s:147)
Thread 3:
0 libsystem_kernel.dylib 0x20d6b864 __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x20e11b34 _pthread_wqthread + 1036 (pthread.c:1999)
2 libsystem_pthread.dylib 0x20e11718 start_wqthread + 8 (pthread_asm.s:147)
Thread 4:
0 libsystem_kernel.dylib 0x20d6b864 __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x20e11b34 _pthread_wqthread + 1036 (pthread.c:1999)
2 libsystem_pthread.dylib 0x20e11718 start_wqthread + 8 (pthread_asm.s:147)
Thread 5:
0 libsystem_kernel.dylib 0x20d6b864 __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x20e11b34 _pthread_wqthread + 1036 (pthread.c:1999)
2 libsystem_pthread.dylib 0x20e11718 start_wqthread + 8 (pthread_asm.s:147)
Thread 6:
0 libsystem_kernel.dylib 0x20d6b864 __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x20e11b34 _pthread_wqthread + 1036 (pthread.c:1999)
2 libsystem_pthread.dylib 0x20e11718 start_wqthread + 8 (pthread_asm.s:147)
Thread 0 crashed with ARM Thread State (32-bit):
r0: 0x00000000 r1: 0x00000000 r2: 0x00000000 r3: 0x20cf1b1d
r4: 0x00000006 r5: 0x38084000 r6: 0x372c2304 r7: 0x002b44e8
r8: 0x1778f4e0 r9: 0x208708fd r10: 0x398938a5 r11: 0x1778f504
ip: 0x00000148 sp: 0x002b44dc lr: 0x20e14733 pc: 0x20d6ac5c
cpsr: 0x00000010
Binary Images:
I have a feeling that this crash may happen when one of my VIPER modules is getting called. It should work this way:
Current view controller (MVC) assembles module by calling this method:
class PeriodPickerAssembly: NSObject {
static func assembleModule() -> PeriodPickerRouter {
let router = PeriodPickerRouter()
let presenter = PeriodPickerPresenter()
let viewController = UIStoryboard.init(name: "PeriodPicker", bundle: nil).instantiateViewController(withIdentifier: "PeriodPickerViewController") as! PeriodPickerViewController
viewController.periodPickerPresenter = presenter
presenter.view = viewController
presenter.router = router
router.presenter = presenter
router.view = viewController
return router
}
}
Then method choosePeriodWithParams shows view as popover:
class PeriodPickerRouter: NSObject, PeriodPickerRouterInterface, PeriodPickerInterface {
weak var presenter: PeriodPickerPresenter!
weak var delegate: PeriodPickerDelegate!
weak var view : UIViewController!
// Ingoing
func choosePeriodWithParams(startDateLimit: Date?, endDateLimit: Date?, currentStartDate: Date?, currentEndDate: Date?) {
view.modalPresentationStyle = .popover
view.popoverPresentationController?.sourceView = UIApplication.topViewController()?.view
appDelegate.window?.rootViewController?.present(view!, animated: true, completion: nil)
presenter.configureDatePickers(startDateLimit: startDateLimit, endDateLimit: endDateLimit, currentStartDate: currentStartDate, currentEndDate: currentEndDate)
}
// Outgoing
func dismissPeriodPicker() {
view.dismiss(animated: true, completion: nil)
}
func periodPickerDidChoosePeriod(startDate: Date, endDate: Date) {
delegate.periodPickerDidChoosePeriod(startDate: startDate, endDate: endDate)
view.dismiss(animated: true, completion: nil)
}}
I think that these two lines can be related to the issue. But not sure how to prove it:
view.popoverPresentationController?.sourceView = UIApplication.topViewController()?.view
appDelegate.window?.rootViewController?.present(view!, animated: true, completion: nil)
Finally I have found the issue during testing. And it's stupid and well-known issue (Shame on me, I forgot to test my app on iPads properly). But I still do not understand how to analyse that crash report.
Error has the same text, except line numbers (it's okay, because code changed and I had this issue with different popovers).
2018-09-27 22:37:53.952 CafeManager[5235:253337] *** Terminating app due to uncaught exception 'NSGenericException', reason: 'Your application has presented a UIAlertController (<UIAlertController: 0x7fd2a0335c90>) of style UIAlertControllerStyleActionSheet. The modalPresentationStyle of a UIAlertController with this style is UIModalPresentationPopover. You must provide location information for this popover through the alert controller's popoverPresentationController. You must provide either a sourceView and sourceRect or a barButtonItem. If this information is not known when you present the alert controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.'
*** First throw call stack:
(
0 CoreFoundation 0x00000001099a6d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000109094deb objc_exception_throw + 48
2 UIKit 0x000000010ae3d396 -[UIPopoverPresentationController presentationTransitionWillBegin] + 3407
3 UIKit 0x000000010a5d3f44 __71-[UIPresentationController _initViewHierarchyForPresentationSuperview:]_block_invoke + 2035
4 UIKit 0x000000010a5d1b76 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 309
5 UIKit 0x000000010a46ff62 _runAfterCACommitDeferredBlocks + 317
6 UIKit 0x000000010a483e4c _cleanUpAfterCAFlushAndRunDeferredBlocks + 95
7 UIKit 0x000000010a490147 _afterCACommitHandler + 90
8 CoreFoundation 0x00000001098cbc37 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
9 CoreFoundation 0x00000001098cbba7 __CFRunLoopDoObservers + 391
10 CoreFoundation 0x00000001098c17fb __CFRunLoopRun + 1147
11 CoreFoundation 0x00000001098c10f8 CFRunLoopRunSpecific + 488
12 GraphicsServices 0x000000010f54cad2 GSEventRunModal + 161
13 UIKit 0x000000010a463f09 UIApplicationMain + 171
14 CafeManager 0x0000000108227134 main + 68
15 libdyld.dylib 0x000000010dd0992d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
UPD:
2018-09-27 22:37:53.952 CafeManager[5235:253337] *** Terminating app due to uncaught exception 'NSGenericException', reason: 'Your application has presented a UIAlertController () of style UIAlertControllerStyleActionSheet. The modalPresentationStyle of a UIAlertController with this style is UIModalPresentationPopover. You must provide location information for this popover through the alert controller's popoverPresentationController. You must provide either a sourceView and sourceRect or a barButtonItem. If this information is not known when you present the alert controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.'
Presenting a UIAlertController properly on an iPad using iOS 8
I hope it will help somebody.