iOS application crash while show popover - ios

In application rootviewController allocated like
navigationContr = [[UINavigationController alloc] initWithRootViewController:loginViewController];
loginViewController = nil;
self.window.rootViewController = _navigationViewController;
After login I push MainViewController like this
MainViewController * mainViewController = [[MainViewController alloc]initWithNibName:#"MainViewController" bundle:nil];
mainViewController.isNavigateFromLogin = YES;
/** push the Main screen*/
[self.navigationController pushViewController:mainViewController animated:NO];
mainViewController = nil;
On MainViewController I am adding view of another viewController like this
gridViewControllerObj = [[GridViewController alloc]initWithNibName:#"GridViewController" bundle:nil];
[self.view addSubview:gridViewControllerObj.view];
GridViewController added on button, on button click we showed popover. Code below
Memory allocated to "operationsViewController"
self.optionsPopOver = [[UIPopoverController alloc]initWithContentViewController:operationsViewController];
[_orderOptionsPopOver presentPopoverFromRect:frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown|UIPopoverArrowDirectionUp animated:NO];
This is flow of show popover,if run app on device I see warning print on console. After time out I go back to first view
Issue 1:
BusinessApplication[8321] : Presenting view controllers on detached view controllers is discouraged .
For this case app work but not crash
To fix this warning ,I searched on forum for above warning, there are solution suggested like
AppDelegate *appDelegate = (AppDelegate* )[[UIApplication sharedApplication] delegate];
UIView *rootView = appDelegate.window.rootViewController.view;
After providing rootview to popover above warning goes of
[_orderOptionsPopOver presentPopoverFromRect:frame inView:rootView permittedArrowDirections:UIPopoverArrowDirectionDown|UIPopoverArrowDirectionUp animated:NO];
Issue 2:
After apply of above solution on time out application get crashed.
I got following crash log
BusinessApplication[511] <Warning>: Warning: sync SCNetworkReachability (by-name) query on main thread
mstreamd[513] <Notice>: (Note ) PS: MSSubscriber - 1456278278 Finished retrieving assets. Checking for errors on 0 assets...
BusinessApplication[511] <Warning>: Warning: sync SCNetworkReachability (by-name) query on main thread
BusinessApplication[511] <Warning>: Warning: sync SCNetworkReachability (by-name) query on main thread
BusinessApplication[511] <Warning>: Stack Trace: uncaughtExceptionHandler
(
0 CoreFoundation 0x25f0fd7f <redacted> + 150
1 libobjc.A.dylib 0x33aefc77 objc_exception_throw + 38
2 UIKit 0x29696533 <redacted> + 2918
3 UIKit 0x2969809b <redacted> + 94
4 UIKit 0x293c11a1 <redacted> + 72
5 UIKit 0x29697fcf <redacted> + 198
6 UIKit 0x2949c199 <redacted> + 168
7 UIKit 0x294c5741 <redacted> + 116
8 UIKit 0x294c4721 <redacted> + 120
9 UIKit 0x294037a3 <redacted> + 66
10 Foundation 0x26c16dc9 __NSFireDelayedPerform + 468
11 CoreFoundation 0x25ed6517 <redacted> + 14
12 CoreFoundation 0x25ed6099 <redacted> + 656
13 CoreFoundation 0x25ed4303 <redacted> + 1418
14 CoreFoundation 0x25e21981 CFRunLoopRunSpecific + 476
15 CoreFoundation 0x25e21793 CFRunLoopRunInMode + 106
16 GraphicsServices 0x2d1b1051 GSEventRunModal + 136
17 UIKit 0x29413981 UIApplicationMain + 1440
18 BusinessApplication 0x003ddc17 main + 170
19 libdyld.dylib 0x3408baaf <redacted> + 2
)
BusinessApplication[511] <Warning>: CRASH: Application tried to present modally an active controller <MainViewController: 0x16a78b30>.
BusinessApplication[511] <Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <MainViewController: 0x16a78b30>.'
*** First throw call stack:
(0x25f0fd67 0x33aefc77 0x29696533 0x2969809b 0x293c11a1 0x29697fcf 0x2949c199 0x294c5741 0x294c4721 0x294037a3 0x26c16dc9 0x25ed6517 0x25ed6099 0x25ed4303 0x25e21981 0x25e21793 0x2d1b1051 0x29413981 0x3ddc17 0x3408baaf)
ReportCrash[516] <Error>: task_set_exception_ports(B07, 400, D03, 0, 0) failed with error (4: (os/kern) invalid argument)
ReportCrash[516] <Notice>: ReportCrash acting against PID 511
ReportCrash[516] <Notice>: Formulating crash report for process BusinessApplication[511]
mediaserverd[36] <Notice>: '' com.xp.businessApp(pid = 511) setting DiscoveryMode = DiscoveryMode_None, currentDiscoveryMode = DiscoveryMode_None
com.apple.xpc.launchd[1] (UIKitApplication:com.xp.businessApp[0x2b0f][511]) <Notice>: Service exited due to signal: Abort trap: 6
<Warning>: Application 'UIKitApplication:com.xp.businessApp[0x2b0f]' crashed.
assertiond[54] <Warning>: pid_suspend failed for <BKNewProcess: 0x16d885d0; com.xp.businessApp; pid: 511>: Unknown error: -1, Unknown error: -1
assertiond[54] <Warning>: Could not set priority of <BKNewProcess: 0x16d885d0; com.xp.businessApp; pid: 511> to 2, priority: No such process
assertiond[54] <Warning>: Could not set priority of <BKNewProcess: 0x16d885d0; com.xp.businessApp; pid: 511> to 4096, priority: No such process
UserEventAgent[17] <Warning>: id=com.xp.businessApp pid=511, state=0
ReportCrash[516] <Notice>: Saved report to /var/mobile/Library/Logs/CrashReporter/BusinessApplication_2015-03-14-171423_IPad.ips
locationd[60] <Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0
locationd[60] <Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0
mstreamd[513] <Notice>: (Note ) mstreamd: Not monitoring for external power.
mstreamd[513] <Notice>: (Note ) PS: Media stream daemon stopping.
mstreamd[513] <Notice>: (Note ) AS: <MSIOSAlbumSharingDaemon: 0x14e30790>: Shared Streams daemon has shut down.
mstreamd[513] <Notice>: (Warn ) mstreamd: mstreamd shutting down.
<Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0
<Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0
locationd[60] <Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0
locationd[60] <Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0

The problem in what you're doing is that you've created a pitfall chain for yourself.
You create a couple of controllers, and present them, but after you present them, you deallocate them. You can't present something you deallocate. This leads to the first issue, trying to present another controller when your current controller is nil.
Next, you take the error message and search for a solution out of context. That is not a solution to your problem and obviously it will lead to a crash if you try and use it.
The first thing you need to do is to remove the nil assign. I don't know why you're doing it and I'm certain its causing many problems.
When you have *a = *b, and *c = *a, if you set c = nil, all of the rest of the variables will be nil as well because its how pointers work. I'm happy to help you some more if you don't mind somebody looking at your code, but I can't do much if problematic calls are still in there.

Related

iOS app crashes with EXC_BREAKPOINT (SIGTRAP) in AppDelegate.applicationWillResignActive

I have an app with very strange crashes that I have been unable to reproduce. I see these crashes in Xcode Organizer and in AppStore connect but not in crash tools (I tried Sentry and Bugsnag).
As far as I understand crash logs, crash occurs in applicationWillResignActive.
Incident Identifier: A15332F7-C7E6-4618-9FEF-7A2E6AD013FF
Hardware Model: iPhone14,5
Process: MyApp [1533]
Path: /private/var/containers/Bundle/Application/408766C6-5645-4592-9D89-CB8DE5D71A76/MyApp.app/MyApp
Identifier: com.myapp.identifier
Version: 1.2.3 (123)
AppStoreTools: 13A1030d
AppVariant: 1:iPhone14,5:15
Code Type: ARM-64 (Native)
Role: Non UI
Parent Process: launchd [1]
Coalition: com.myapp.identifier [899]
Date/Time: 2021-11-12 08:04:45.3781 +0300
Launch Time: 2021-11-12 01:20:00.0202 +0300
OS Version: iPhone OS 15.0 (19A346)
Release Type: User
Baseband Version: 1.00.03
Report Version: 104
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x0000000100602734
Exception Note: EXC_CORPSE_NOTIFY
Terminating Process: exc handler [1533]
Triggered by Thread: 0
Thread 0 name:
Thread 0 Crashed:
0 MyApp 0x0000000100602734 specialized AppDelegate.applicationWillResignActive(_:) + 168
1 MyApp 0x00000001005ff40c AppDelegate.applicationWillTerminate(_:) + 12 (<compiler-generated>:0)
2 MyApp 0x00000001005ff40c #objc AppDelegate.applicationWillTerminate(_:) + 56
3 UIKitCore 0x0000000186a34ddc -[UIApplication _terminateWithStatus:] + 244 (UIApplication.m:6876)
4 UIKitCore 0x0000000186122854 -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:] + 128 (_UISceneLifecycleMultiplexer.m:808)
5 UIKitCore 0x00000001863172e4 -[_UISceneLifecycleMultiplexer forceExitWithTransitionContext:scene:] + 224 (_UISceneLifecycleMultiplexer.m:482)
6 UIKitCore 0x0000000186a31a5c -[UIApplication workspaceShouldExit:withTransitionContext:] + 212 (UIApplication.m:3792)
7 FrontBoardServices 0x0000000195150c48 __63-[FBSWorkspaceScenesClient willTerminateWithTransitionContext:]_block_invoke_2 + 80 (FBSWorkspaceScenesClient.m:331)
8 FrontBoardServices 0x000000019510b6c4 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 240 (FBSWorkspace.m:352)
9 FrontBoardServices 0x0000000195150be0 __63-[FBSWorkspaceScenesClient willTerminateWithTransitionContext:]_block_invoke + 132 (FBSWorkspaceScenesClient.m:328)
10 libdispatch.dylib 0x0000000183346950 _dispatch_client_callout + 20 (object.m:560)
11 libdispatch.dylib 0x000000018334a3e8 _dispatch_block_invoke_direct + 264 (queue.c:489)
12 FrontBoardServices 0x000000019510cfa4 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 48 (FBSSerialQueue.m:157)
13 FrontBoardServices 0x000000019510c3e4 -[FBSSerialQueue _targetQueue_performNextIfPossible] + 220 (FBSSerialQueue.m:181)
14 FrontBoardServices 0x00000001951109f4 -[FBSSerialQueue _performNextFromRunLoopSource] + 28 (FBSSerialQueue.m:194)
15 CoreFoundation 0x00000001836f6030 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 (CFRunLoop.c:1972)
16 CoreFoundation 0x0000000183706cf0 __CFRunLoopDoSource0 + 208 (CFRunLoop.c:2016)
17 CoreFoundation 0x0000000183640ff8 __CFRunLoopDoSources0 + 268 (CFRunLoop.c:2053)
18 CoreFoundation 0x0000000183646804 __CFRunLoopRun + 820 (CFRunLoop.c:2951)
19 CoreFoundation 0x000000018365a3c8 CFRunLoopRunSpecific + 600 (CFRunLoop.c:3268)
20 GraphicsServices 0x000000019ee6b38c GSEventRunModal + 164 (GSEvent.c:2200)
21 UIKitCore 0x00000001860000bc -[UIApplication _run] + 1100 (UIApplication.m:3457)
22 UIKitCore 0x0000000185d7dbe8 UIApplicationMain + 2124 (UIApplication.m:5013)
23 MyApp 0x00000001004a5b18 main + 68 (AppDelegate.swift:19)
24 dyld 0x000000010092da24 start + 520 (dyldMain.cpp:876)
Inside applicationWillResignActive I am fetching data from my local Realm and update values in UserDefaults.
class AppDelegate: UIResponder, UIApplicationDelegate {
let provider = Provider()
func applicationWillResignActive(_ application: UIApplication) {
if userDefaults.bool(forKey: UserDefaults.Keys.keyWidgetEnabled) {
provider.updateUserDefaults()
}
}
}
class Provider {
let database = try! Realm()
...
func updateUserDefaults() {
let defaults = UserDefaults(suiteName: "com.MyApp.identifier")
let currentDisplayDate = CalculationsHelper.getUTCSubmitDate()
let predicateHistoryDisplayDate = NSPredicate(format: "type=%# AND currentSubmitDate = %#", keyDBFood, currentDisplayDate.absoluteDate as NSDate)
let data = self.database.objects(History.self).filter(predicateHistoryDisplayDate)
mealTypesDB.allFoodTypes.forEach{ (type) in
let key = "widget-" + type.rawValue
let predicate = NSPredicate(format: "meal=%#", type.rawValue)
let kcal: Int = data.filter(predicate).sum(ofProperty: "kcal")
defaults?.set(kcal, forKey: key)
}
//set the date of the next day to update the button
let currentSubmitDate = CalculationsHelper.getLocalSubmitDate()
defaults?.set(currentSubmitDate, forKey: "widget-submitDate")
defaults?.synchronize()
if #available(iOS 14.0, *) {
WidgetCenter.shared.reloadAllTimelines()
}
}
}
I used to do this for every user every time they sent the app to background, but for a week now I've only done it for the small fraction of users who have my widget installed. But number of crashes almost didn't change so I think that this bug is not related with Realm or UserDefaults.
As far as I can tell from AppStore connect, I've always had this bug, but only with the release of iOS 15 has the number of crashes dramatically increased. I'm not really sure how this can be resolved and what exactly has changed in iOS 15 that could provoke such a dramatic increase number of crashes.
I found this thread https://developer.apple.com/forums/thread/106261 and tried renaming all my images in the project so that the file names match the name in Assets, but that didn't work.
Does anyone have any idea what I can do to at least figure out the cause of the crashes?
I contacted Apple TSI and they told me to check that the object inside the applicationWillResignActive and applicationWillTerminate method is nil. And to my surprise at the moment of calling applicationWillTerminate the object is really nil.
But can anyone explain how this is possible? This object is initialised in didFinishLaunchingWithOptions and I never make it equal to nil during the app life cycle. Is it possible that iOS is trying to terminate the application for some reason (not enough memory, for example) and tries to remove all objects from memory one by one, and when applicationWillTerminate is called, object is already removed from memory and therefore it is nil? But at which point it's allowed to nil out a variable of a running class?
UPDATE:
I got a response from the Apple team and I think it's very interesting. They said that didFinishLaunchingWithOptions will ALWAYS be called before other lifecycle delegates for
the "standard" lifecycle like applicationWillResignActive and
applicationDidEnterBackground. However, that's NOT the case with applicationWillTerminate. The
termination process can occur outside the normal lifecycle flow and, at
least in theory, there's not reason it couldn't occur before
didFinishLaunchingWithOptions is actually called.
So if I have an optional variable in AppDelegate that is initialized inside didFinishLaunchingWithOptions, it can still be nil in applicationWillTerminate. This is what causes some users to crash.
Are you calling applicationWillResignActive yourself? It looks like you call it from AppDelegate.applicationWillTerminate. You should never call the UIAppDelegate methods yourself, that is an anti-pattern. I'm not sure that causes the crash though, but you may want to introduce a separate method which you call from both.
The fact that you are using a custom crash reporter (Sentry, Bugsnag, ...) could be an issue. When your app crashes, Apple's crash reporter can get confused and the reported line you get will be completely wrong.
You can find more details provided by an Apple engineer on this Apple dev forum post. He recommends only using Apple's own crash reporter because third-party crash reporters are tied to your app process and can corrupt the stack trace when they try to get it while your app is crashing which results in a wrong report in Xcode.

iOS Simulator gets stuck in an infinite loop

I am using Xcode 9.1, but the following issue happened with Xcode 9 as well.
Sometimes, after running an application in the simulator and stopping the execution from Xcode, the simulator gets stuck in a loop and opens/closes the same application rapidly and endlessly.
The fix that I know for this issue is running an application from Xcode again or quitting the simulator.
It seems like the OS of the simulator is not a key factor, it already happened with multiple different simulators.
If I try to close the application by pressing the Home button, SpringBoard throws a crash:
Here is a relevant snippet from the crash:
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Application Specific Information:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'need the old view controller for <SBLayoutElement: 0x600001a7f3c0; identifier: [application's ID]; layoutRole: primary; layoutElementMode: default> {
supportedLayoutRoles = primary;
layoutAttributes = none;
viewControllerClass = SBMainWorkspaceApplicationSceneLayoutElementViewController;
}'
terminating with uncaught exception of type NSException
abort() called
CoreSimulator 494.22.7 - Device: iPhone 6 - Runtime: iOS 11.1 (15B87) - DeviceType: iPhone 6
Application Specific Backtrace 1:
0 CoreFoundation 0x0000000115bc61ab __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000011525bf41 objc_exception_throw + 48
2 CoreFoundation 0x0000000115bcb372 +[NSException raise:format:arguments:] + 98
3 Foundation 0x0000000111085089 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
4 SpringBoard 0x0000000108e5f17a SpringBoard + 2863482
5 SpringBoard 0x00000001090980bc SpringBoard + 5193916
6 SpringBoard 0x0000000108e5e9c9 SpringBoard + 2861513
7 SpringBoard 0x00000001090be78d SpringBoard + 5351309
8 SpringBoard 0x0000000108e60902 SpringBoard + 2869506
9 SpringBoard 0x0000000108e17094 SpringBoard + 2568340
10 SpringBoard 0x0000000108f5d197 SpringBoard + 3903895
11 SpringBoard 0x0000000108f5d253 SpringBoard + 3904083
12 SpringBoard 0x0000000108f5d86b SpringBoard + 3905643
13 SpringBoard 0x0000000108f5c4a0 SpringBoard + 3900576
14 SpringBoard 0x0000000108f5aea9 SpringBoard + 3894953
15 BaseBoard 0x000000010e749091 __22-[BSTransaction begin]_block_invoke + 178
16 BaseBoard 0x000000010e74f7b7 -[BSTransaction _preventTransactionCompletionForReason:ignoringAuditHistory:andExecuteBlock:] + 66
17 BaseBoard 0x000000010e748c4b -[BSTransaction begin] + 890
18 BaseBoard 0x000000010e749136 __22-[BSTransaction begin]_block_invoke + 343
19 BaseBoard 0x000000010e74f7b7 -[BSTransaction _preventTransactionCompletionForReason:ignoringAuditHistory:andExecuteBlock:] + 66
20 BaseBoard 0x000000010e748c4b -[BSTransaction begin] + 890
21 SpringBoard 0x0000000108beea28 SpringBoard + 305704
22 SpringBoard 0x0000000108bf1875 SpringBoard + 317557
23 SpringBoard 0x0000000108bf1597 SpringBoard + 316823
24 SpringBoard 0x0000000108befee4 SpringBoard + 311012
25 BaseBoard 0x000000010e7569c8 -[BSEventQueue _processNextEvent] + 349
26 SpringBoard 0x0000000108beeb3b SpringBoard + 305979
27 libdispatch.dylib 0x0000000116dd8273 _dispatch_call_block_and_release + 12
28 libdispatch.dylib 0x0000000116dd92b5 _dispatch_client_callout + 8
29 libdispatch.dylib 0x0000000116de3496 _dispatch_main_queue_callback_4CF + 1260
30 CoreFoundation 0x0000000115b88ee9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
31 CoreFoundation 0x0000000115b4d592 __CFRunLoopRun + 2402
32 CoreFoundation 0x0000000115b4c9b9 CFRunLoopRunSpecific + 409
33 GraphicsServices 0x00000001115e89c6 GSEventRunModal + 62
34 UIKit 0x000000010c0fb5e8 UIApplicationMain + 159
35 FrontBoard 0x000000010e4efdfa FBSystemAppMain + 1010
36 libdyld.dylib 0x0000000116e4dd81 start + 1
37 ??? 0x0000000000000001 0x0 + 1
Is there a known fix for this?

Xcode 9.0 Swift 04 (Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only run on the main thread!')

Main Thread Checker: UI API called on a background thread: -[UIView init]
PID: 460, TID: 62011, Thread name: (none), Queue name: com.apple.root.background-qos, QoS: 9
Backtrace:
4 IQKeyboardManagerSwift 0x00000001025c8274 _T0So11UITextFieldCABycfcTO + 28
5 IQKeyboardManagerSwift 0x00000001025a8360 _T0So11UITextFieldCABycfC + 68
6 IQKeyboardManagerSwift 0x00000001025a7e90 _T022IQKeyboardManagerSwift0aB0CACycfc + 5196
7 IQKeyboardManagerSwift 0x00000001025a838c _T022IQKeyboardManagerSwift0aB0CACycfcTo + 28
8 IQKeyboardManagerSwift 0x00000001025a6a3c _T022IQKeyboardManagerSwift0aB0CACycfC + 32
9 IQKeyboardManagerSwift 0x00000001025c5920 globalinit_33_1804EA4A44CDC62F5B66EAD58B4692DC_func2 + 24
10 libdispatch.dylib 0x00000001043e545c _dispatch_client_callout + 16
11 libdispatch.dylib 0x00000001043e617c dispatch_once_f + 120
12 IQKeyboardManagerSwift 0x000000010259c4cc _T022IQKeyboardManagerSwift0aB0C06sharedB0ACyFZ6StaticL_V02kbB0ACfau + 56
13 IQKeyboardManagerSwift 0x000000010259c46c _T022IQKeyboardManagerSwift0aB0C06sharedB0ACyFZ + 24
14 eBeePartners 0x0000000100c9ef7c _T012eBeePartners11AppDelegateC11applicationSbSo13UIApplicationC_s10DictionaryVySC0F16LaunchOptionsKeyVypGSg022didFinishLaunchingWithI0tFyycfU_ + 52
15 eBeePartners 0x0000000100bd18c0 _T0Ix_IyB_TR + 48
16 libdispatch.dylib 0x00000001043e549c _dispatch_call_block_and_release + 24
17 libdispatch.dylib 0x00000001043e545c _dispatch_client_callout + 16
18 libdispatch.dylib 0x00000001043f6cd8 _dispatch_root_queue_drain + 1004
19 libdispatch.dylib 0x00000001043f6880 _dispatch_worker_thread3 + 136
20 libsystem_pthread.dylib 0x0000000181dab130 _pthread_wqthread + 1268
21 libsystem_pthread.dylib 0x0000000181daac30 start_wqthread + 4
2017-09-22 12:36:11.268059+0800 eBeePartners[460:62011] [reports] Main Thread Checker: UI API called on a background thread: -[UIView init]
PID: 460, TID: 62011, Thread name: (none), Queue name: com.apple.root.background-qos, QoS: 9
Backtrace:
4 IQKeyboardManagerSwift 0x00000001025c8274 _T0So11UITextFieldCABycfcTO + 28
5 IQKeyboardManagerSwift 0x00000001025a8360 _T0So11UITextFieldCABycfC + 68
6 IQKeyboardManagerSwift 0x00000001025a7e90 _T022IQKeyboardManagerSwift0aB0CACycfc + 5196
7 IQKeyboardManagerSwift 0x00000001025a838c _T022IQKeyboardManagerSwift0aB0CACycfcTo + 28
8 IQKeyboardManagerSwift 0x00000001025a6a3c _T022IQKeyboardManagerSwift0aB0CACycfC + 32
9 IQKeyboardManagerSwift 0x00000001025c5920 globalinit_33_1804EA4A44CDC62F5B66EAD58B4692DC_func2 + 24
10 libdispatch.dylib 0x00000001043e545c _dispatch_client_callout + 16
11 libdispatch.dylib 0x00000001043e617c dispatch_once_f + 120
12 IQKeyboardManagerSwift 0x000000010259c4cc _T022IQKeyboardManagerSwift0aB0C06sharedB0ACyFZ6StaticL_V02kbB0ACfau + 56
13 IQKeyboardManagerSwift 0x000000010259c46c _T022IQKeyboardManagerSwift0aB0C06sharedB0ACyFZ + 24
14 eBeePartners 0x0000000100c9ef7c _T012eBeePartners11AppDelegateC11applicationSbSo13UIApplicationC_s10DictionaryVySC0F16LaunchOptionsKeyVypGSg022didFinishLaunchingWithI0tFyycfU_ + 52
15 eBeePartners 0x0000000100bd18c0 _T0Ix_IyB_TR + 48
16 libdispatch.dylib 0x00000001043e549c _dispatch_call_block_and_release + 24
17 libdispatch.dylib 0x00000001043e545c _dispatch_client_callout + 16
18 libdispatch.dylib 0x00000001043f6cd8 _dispatch_root_queue_drain + 1004
19 libdispatch.dylib 0x00000001043f6880 _dispatch_worker_thread3 + 136
20 libsystem_pthread.dylib 0x0000000181dab130 _pthread_wqthread + 1268
21 libsystem_pthread.dylib 0x0000000181daac30 start_wqthread + 4
2017-09-22 12:36:22.758673+0800 eBeePartners[460:61967] [BoringSSL] Function nw_protocol_boringssl_input_finished: line 1389 Peer disconnected during the middle of a handshake. Sending errSSLFatalAlert(-9802) alert
2017-09-22 12:36:22.813732+0800 eBeePartners[460:61967] TIC TCP Conn Failed [2:0x1c0166900]: 3:-9802 Err(-9802)
2017-09-22 12:36:22.848609+0800 eBeePartners[460:61719] [MC] Lazy loading NSBundle MobileCoreServices.framework
2017-09-22 12:36:22.854700+0800 eBeePartners[460:61719] [MC] Loaded MobileCoreServices.framework
2017-09-22 12:36:22.864960+0800 eBeePartners[460:61719] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2017-09-22 12:36:22.898137+0800 eBeePartners[460:62011] *** Assertion failure in void _UIPerformResizeOfTextViewForTextContainer(NSLayoutManager *, UIView<NSTextContainerView> *, NSTextContainer *, NSUInteger)(), /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIFoundation/UIFoundation-543/UIFoundation/TextSystem/NSLayoutManager_Private.m:1619
2017-09-22 12:36:23.117424+0800 eBeePartners[460:62011] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only run on the main thread!'
*** First throw call stack:
(0x18217fd38 0x181694528 0x18217fc0c 0x182b0ec90 0x18c65a70c 0x18c65a194 0x18c689e4c 0x18c689b08 0x18c6b3f88 0x18b8ebf28 0x18b5b1218 0x18c1e697c 0x18b6613ec 0x1025c8274 0x1025a8360 0x1025a7e90 0x1025a838c 0x1025a6a3c 0x1025c5920 0x1043e545c 0x1043e617c 0x10259c4cc 0x10259c46c 0x100c9ef7c 0x100bd18c0 0x1043e549c 0x1043e545c 0x1043f6cd8 0x1043f6880 0x181dab130 0x181daac30)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
How to debug this code?
I also had this error ONLY AFTER upgrading to Xcode9/Swift4. As mentioned in comments, the reason is calling ui-operations in background thread. I don't know why it has been working until upgrading.
How to debug
You are seeing this error on Xcode which process frozen by debugger, right? Then, the left side panel (called "debug navigator") is showing call stack and indicating the line where the app crashed. You can click one of them and get the code.
In my case
The cause of error is performSegue attempted to run on the main thread in my case.
func downloadHandler() {
DispatchQueue.global(qos: .default).async(execute: {
DispatchQueue.main.async(execute: {
self.labelMessage.text = "Unzipping downloaded data..."
})
/* Unzipping something... */
// WRONG: This causes error
// self.performSegue(withIdentifier: "toViewController", sender: nil)
// FIXED: performSegue should be run on main thread.
DispatchQueue.main.async(execute: {
self.performSegue(withIdentifier: "toViewController", sender: nil)
})
})
}
Double check your DispatchQueue. It would be better to start at where debugger stopped.

App crashes when Simulator is restarted

I started using facebook SDK and the official react native wrapper.
Am not sure if this is the cause or if its my usage of AsyncStorage. But whenever I quit the simulator and then re-run my app via (react-native run-ios), the app crashes. Everytime I have to "Reset content and settings" for it to go away. Below is the logs I can find.
Dec 10 21:48:34 sseshac-in-la-2 XXXXX[22405] <Error>: assertion failed: 15G1108 14A345: libxpc.dylib + 62597 [37A9DF49-35C1-3D93-B854-B35CACF0100F]: 0x7d
Dec 10 21:48:34 sseshac-in-la-2 Unknown[22405] <Error>:
Dec 10 21:48:34 sseshac-in-la-2 XXXXX[22405] <Error>: [] nw_host_stats_add_src recv too small, received 24, expected 28
--- last message repeated 2 times ---
Dec 10 21:48:34 sseshac-in-la-2 XXXXX[22405] <Notice>: Initializing <RCTBatchedBridge: 0x6100001971b0> (parent: <RCTBridge: 0x6080000b9620>, executor: RCTJSCExecutor)
Dec 10 21:48:34 sseshac-in-la-2 XXXXX[22405] <Warning>: Class GenericShare was not exported. Did you forget to use RCT_EXPORT_MODULE()?
Dec 10 21:48:34 sseshac-in-la-2 XXXXX[22405] <Warning>: Class WhatsAppShare was not exported. Did you forget to use RCT_EXPORT_MODULE()?
Dec 10 21:48:34 sseshac-in-la-2 XXXXX[22405] <Warning>: Class GooglePlusShare was not exported. Did you forget to use RCT_EXPORT_MODULE()?
Dec 10 21:48:34 sseshac-in-la-2 XXXXX[22405] <Error>: [] nw_host_stats_add_src recv too small, received 24, expected 28
Dec 10 21:48:34 sseshac-in-la-2 XXXXX[22405] <Warning>: Falling back to loading access token from NSUserDefaults because of simulator bug
Dec 10 21:48:34 sseshac-in-la-2 XXXXX[22405] <Error>: -[NSConcreteMutableData isEqualToString:]: unrecognized selector sent to instance 0x608000050710
Dec 10 21:48:34 sseshac-in-la-2 XXXXX[22405] <Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteMutableData isEqualToString:]: unrecognized selector sent to instance 0x608000050710'
*** First throw call stack:
(
0 CoreFoundation 0x00000001020c834b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000100fd821e objc_exception_throw + 48
2 CoreFoundation 0x0000000102137f34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000010204dc15 ___forwarding___ + 1013
4 CoreFoundation 0x000000010204d798 _CF_forwarding_prep_0 + 120
5 XXXXX 0x0000000100657170 -[FBSDKAccessTokenCacheV4 fetchAccessToken] + 179
6 XXXXX 0x0000000100642526 -[FBSDKAccessTokenCache fetchAccessToken] + 73
7 XXXXX 0x000000010064cfbb -[FBSDKApplicationDelegate application:didFinishLaunchingWithOptions:] + 97
8 XXXXX 0x00000001004c7552 -[AppDelegate application:didFinishLaunchingWithOptions:] + 898
9 UIKit 0x000000010476768e -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 290
10 UIKit 0x0000000104769013 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4236
11 UIKit 0x000000010476f3b9 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1731
12 UIKit 0x000000010476c539 -[UIApplication workspaceDidEndTransaction:] + 188
13 FrontBoardServices 0x0000000107bf176b __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
14 FrontBoardServices 0x0000000107bf15e4 -[FBSSerialQueue _performNext] + 189
15 FrontBoardServices 0x0000000107bf196d -[FBSSerialQueue _performNextFromRunLoopSource] + 45
16 CoreFoundation 0x000000010206d311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
17 CoreFoundation 0x000000010205259c __CFRunLoopDoSources0 + 556
18 CoreFoundation 0x0000000102051a86 __CFRunLoopRun + 918
19 CoreFoundation 0x0000000102051494 CFRunLoopRunSpecific + 420
20 UIKit 0x000000010476adb6 -[UIApplication _run] + 434
21 UIKit 0x0000000104770f34 UIApplicationMain + 159
22 XXXXX 0x00000001004c788f main + 111
23 libdyld.dylib 0x000000010613b68d start + 1
)
Dec 10 21:48:34 sseshac-in-la-2 SpringBoard[22278] <Error>: [KeyboardArbiter] HW kbd: Failed to set (null) as keyboard focus
Dec 10 21:48:34 sseshac-in-la-2 com.apple.CoreSimulator.SimDevice.B70B2265-1548-4811-B873-564E3E5DAFCB.launchd_sim[22261] (UIKitApplication:org.reactjs.native.example.XXXXX[0xe405][22405]) <Notice>: Service exited due to Abort trap: 6
Dec 10 21:48:34 sseshac-in-la-2 assertiond[22282] <Warning>: notify_suspend_pid() failed with error 7

Strange crash when presenting modal UIViewController

I've seen this crash report a few times. It is extremely random and rare, and I can't understand it. All I am doing is presenting a modal view controller using the following code
ComposeController *newcontrol = [[ComposeController alloc]initWithMode:1 withNIB:#"ComposeController"];
newcontrol.delegate = self;
UINavigationController *holder = [[UINavigationController alloc] initWithRootViewController:newcontrol];
[self presentViewController:holder animated:YES completion:NULL];
Somehow this leads to this completely at random:
OS Version: iPhone OS 6.1 (10B143)
Report Version: 104
Exception Type: SIGSEGV
Exception Codes: SEGV_ACCERR at 0x9
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x3b25c5d0 objc_msgSend + 16
1 CoreFoundation 0x334ba73f -[__NSPlaceholderArray initWithObjects:count:] + 271
2 CoreFoundation 0x334bae09 +[NSArray arrayWithObject:] + 45
3 UIKit 0x353e80ab -[UIWindow _rotationViewControllers] + 51
4 UIKit 0x353e7fe3 -[UIViewController viewControllerForRotation] + 91
5 UIKit 0x353e7f39 -[UIViewController _visibleView] + 97
6 UIKit 0x3546c05b -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 2483
7 UIKit 0x3546afab -[UIViewController presentViewController:withTransition:completion:] + 3399
8 MyApp 0x00046e97 -[Inbox composeHit] (Inbox.m:207)
I have the same problem quite consistently. It seems to be caused by the fact that I am presenting a modal view controller from a popover, which is not well tested and triggers a bug in Apple's code. The bug is that UIKit keeps an unretained reference to my View Controller which has been already dismissed and deallocated, so at a later time that reference is hit. My workaround is either to avoid presenting modal VCs from a popover, or to retain all such VCs myself indefinitely (in a member variable or some such).
Below are the gory details.
Here is the code I used to trigger the problem.
-(void) handlePinchFromCell:(AMPSupportingPhotoCell*) cell
{
UIViewController * vc = [[UIViewController alloc] init]; // UIViewController #0
[self presentViewController:vc animated:YES completion:nil];
[self performSelector:#selector(dismiss:) withObject:vc afterDelay:2];
}
-(void) dismiss:(UIViewController*)vc
{
[self dismissViewControllerAnimated:YES completion:^(){NSLog(#"-------");}];
}
This code is a part of a UIViewController #1, that is inside a UIPopoverController, that is popped over from another UIViewController #2, which is itself a presented from yet another view UIViewController #3. The crash happens after popover is closed, controller #2 id dismissed.
If I enable Zombies, I get the same stack trace but with a message:
2013-03-13 20:04:24.681 Mercury[16698:19d03] handlePinchFromCell: a225710
2013-03-13 20:04:27.083 Mercury[16698:19d03] -------
2013-03-13 20:04:31.606 Mercury[16698:19d03] *** -[UIViewController retain]: message sent to deallocated instance 0xa225710
So, notice that the VC #0 got allocated, presented, dismissed 2 seconds later, deallocated, and yet there is still a dangling reference to it somewhere in the Apple's code. When popover is closed and VC#2 is dismissed, the whole thing comes crashing down trying to access the deallocated VC. I am fairly certain this is Apple's bug. I also guess it's related to presenting a VC from a popover, so if you stay away from that, or retain the VC yourself you should be fine.
Another stack trace for the same problem is this. It happens if the above code is run twice:
2013-03-13 20:12:53.883 Mercury[16735:19d03] handlePinchFromCell: 16d54da0
2013-03-13 20:12:56.285 Mercury[16735:19d03] -------
2013-03-13 20:13:03.481 Mercury[16735:19d03] handlePinchFromCell: a2565f0
2013-03-13 20:13:03.481 Mercury[16735:19d03] *** -[UIViewController isKindOfClass:]: message sent to deallocated instance 0x16d54da0
(lldb) bt
* thread #1: tid = 0x1f03, 0x017f8a97 CoreFoundation`___forwarding___ + 295, stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
frame #0: 0x017f8a97 CoreFoundation`___forwarding___ + 295
frame #1: 0x017f894e CoreFoundation`_CF_forwarding_prep_0 + 14
frame #2: 0x00c42f90 UIKit`-[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 907
frame #3: 0x00a40ee3 UIKit`-[UIViewController presentViewController:withTransition:completion:] + 4521
frame #4: 0x00a41167 UIKit`-[UIViewController presentViewController:animated:completion:] + 112
frame #5: 0x0006c32d Mercury`-[AMPSupportingPhotosViewController handlePinchFromCell:](self=0x16d55360, _cmd=0x0007a64a, cell=0x0a22a2a0) + 205 at AMPSupportingPhotosViewController.m:184
frame #6: 0x015336b0 libobjc.A.dylib`-[NSObject performSelector:withObject:] + 70
frame #7: 0x0006f317 Mercury`-[AMPSupportingPhotoCell handlePinch:](self=0x0a22a2a0, _cmd=0x00efb0db, sender=0x0a2504a0) + 215 at AMPSupportingPhotoCell.m:53
frame #8: 0x00c2185a UIKit`_UIGestureRecognizerSendActions + 139
Try doing this
[holder pushViewController:newcontrol animated:YES completion:NULL];

Resources