Firebase App configuration crash - ios

I have a custom keyboard for iOS that uses Firebase for analytics. The Firebase app configuration is done at the initializer with a dispatch_once clause with the token as a global variable.
var token: dispatch_once_t = 0
class KeyboardViewController: UIInputViewController {
// ..
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
dispatch_once(&token) {
FIRApp.configure()
} // line 90
}
// ..
}
This is working fine but I am receiving many crash reports that indicate crashes on many devices when the app is configured. I am stuck for days trying to figure out the cause. Here is a part of one of the crash reports stack trace:
Exception Type: EXC_CRASH (SIGQUIT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Termination Signal: Quit: 3
Termination Reason: Namespace SIGNAL, Code 0x3
Terminating Process: launchd [1]
Triggered by Thread: 0
Thread 0 name:
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x000000018fab6338 __semwait_signal_nocancel + 8
1 libsystem_c.dylib 0x000000018f9e20dc nanosleep$NOCANCEL + 200 (nanosleep.c:104)
2 libsystem_c.dylib 0x000000018fa0568c sleep$NOCANCEL + 44 (sleep.c:62)
3 libsystem_dnssd.dylib 0x000000018fa6e7d4 ConnectToServer + 832 (dnssd_clientstub.c:607)
4 libsystem_dnssd.dylib 0x000000018fa6ff44 DNSServiceCreateConnection + 76 (dnssd_clientstub.c:1785)
5 libsystem_network.dylib 0x000000018fb2d318 __nw_resolver_set_update_handler_block_invoke + 872 (resolver.m:1031)
6 libdispatch.dylib 0x000000018f9711c0 _dispatch_client_callout + 16 (object.m:455)
7 libdispatch.dylib 0x000000018f97e860 _dispatch_barrier_sync_f_invoke + 84 (queue.c:3457)
8 libsystem_network.dylib 0x000000018fb2ce78 nw_resolver_set_update_handler + 208 (resolver.m:1275)
9 SystemConfiguration 0x0000000190f8a16c __SCNetworkReachabilityRestartResolver + 260 (SCNetworkReachability.c:1711)
10 SystemConfiguration 0x0000000190f891c8 __SCNetworkReachabilitySetDispatchQueue + 764 (SCNetworkReachability.c:1823)
11 SystemConfiguration 0x0000000190f88ccc SCNetworkReachabilityScheduleWithRunLoop + 504 (SCNetworkReachability.c:1586)
12 CustomKeyboard 0x000000010013f630 -[FIRReachabilityChecker start] + 196
13 CustomKeyboard 0x000000010013abac -[FIRNetwork init] + 156
14 CustomKeyboard 0x0000000100132e28 -[FIRClearcutLogger init] + 416
15 CustomKeyboard 0x0000000100132c68 __35+[FIRClearcutLogger sharedInstance]_block_invoke + 36
16 libdispatch.dylib 0x000000018f9711c0 _dispatch_client_callout + 16 (object.m:455)
17 libdispatch.dylib 0x000000018f971fb4 dispatch_once_f + 56 (once.c:57)
18 CustomKeyboard 0x0000000100132c40 +[FIRClearcutLogger sharedInstance] + 108
19 CustomKeyboard 0x0000000100137214 +[FIRApp initClearcut] + 60
20 CustomKeyboard 0x0000000100136688 +[FIRApp configureDefaultAppWithOptions:sendingNotifications:] + 132
21 CustomKeyboard 0x000000010013643c +[FIRApp configure] + 316
22 libdispatch.dylib 0x000000018f9711c0 _dispatch_client_callout + 16 (object.m:455)
23 libdispatch.dylib 0x000000018f971fb4 dispatch_once_f + 56 (once.c:57)
24 CustomKeyboard 0x00000001000e314c _TFC19CustomKeyboard22KeyboardViewControllercfT7nibNameGSqSS_6bundleGSqCSo8NSBundle__S0_ + 1500 (KeyboardViewController.swift:90)
25 CustomKeyboard 0x00000001000e3270 _TToFC19CustomKeyboard22KeyboardViewControllercfT7nibNameGSqSS_6bundleGSqCSo8NSBundle__S0_ + 112 (KeyboardViewController.swift:0)
26 UIKit 0x00000001971f7688 -[_UIViewServiceViewControllerOperator __createViewController:withContextToken:fbsDisplays:appearanceSerializedRepresentations:legacyAppearance:traitCollection:initialInterfaceOrientation:hostAccessibilityServerPort:canShowTextServices:replyHandler:] + 2216 (UIViewServiceViewControllerOperator.m:1732)
27 CoreFoundation 0x0000000190aee160 __invoking___ + 144
28 CoreFoundation 0x00000001909e1c3c -[NSInvocation invoke] + 284 (NSForwarding.m:2948)
29 CoreFoundation 0x00000001909e66ec -[NSInvocation invokeWithTarget:] + 60 (NSForwarding.m:3019)
Apparently, the call trace after calling FIRApp.configure() is going through system libraries.
One observation from the stack trace is that the crash has something to do with checking the reachability of the device. However, I tried to reproduce a scenario where there is no internet connection but it's working fine.
Please note that all the crashes are happening on iOS 10 and most of them on iPhone 6.
Any help to figure out the cause of the crashes would be appreciated.

It is not recommended to use Firebase Analytics in an extension as the SDK does not support extension well. App extensions have limited functionalities compared to a full app so Firebase Analytics may not work well under some conditions, like the network in this case. The team is looking into supporting extensions better later.
It seems like the network is not available on custom keyboard as stated by Apple
"By default, a keyboard has no network access and cannot share a
container with its containing app. To enable these things, set the
value of the RequestsOpenAccess Boolean key in the Info.plist file to
YES. Doing this expands the keyboard’s sandbox, as described in
Designing for User Trust."
https://developer.apple.com/library/content/documentation/General/Conceptual/ExtensibilityPG/CustomKeyboard.html#//apple_ref/doc/uid/TP40014214-CH16-SW1

Related

How to initialize a CLLocationCoordinate2D struct [duplicate]

This question already has answers here:
CLLocationCoordinate2D can't be instantiated
(2 answers)
Closed 1 year ago.
I'm trying to initialize a CLLocationCoordinate2D from a Swift Playground, and I'm getting the error:
error: Execution was interrupted, reason: signal SIGABRT.
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.
Not sure what I'm doing wrong. Here is what I tried:
var temporaryCoordinate = CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0)
You have found a very unusual and interesting bug. I can reproduce your problem by running the following code in a Blank iOS playground:
import UIKit
import CoreLocation
var temporaryCoordinate = CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0)
What is going wrong is that the runtime environment, the Playground, is itself crashing. In the Mac, in the Console app, with Crash Reports left tab, we can see that the Xcode Playground is crashing.
Process: scratch-playground [1696]
Path: /Users/USER/Library/Developer/XCPGDevices/D22341D9-BFF3-4575-9801-1405F0AA2EA2/data/Containers/Bundle/Application/67A50F6D-18E8-4220-A2EB-8673018601AA/scratch-playground-1381-1.app/scratch-playground
Identifier: scratch-playground
Version: 1.0 (1)
Code Type: ARM-64 (Native)
Parent Process: ??? [1697]
Responsible: SimulatorTrampoline [635]
User ID: 501
Date/Time: 2021-04-06 21:43:05.608 +0100
OS Version: macOS 11.2.3 (20D91)
Report Version: 12
Anonymous UUID: BFEAE183-A757-B843-D9D2-BF254A4665C2
Time Awake Since Boot: 6300 seconds
System Integrity Protection: enabled
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
External Modification Warnings:
Debugger attached to process.
Application Specific Information:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSValue valueWithMKCoordinate:]: unrecognized selector sent to class 0x1c9d3f588'
terminating with uncaught exception of type NSException
abort() called
CoreSimulator 732.18.6 - Device: iPad Pro (9.7-inch) (D22341D9-BFF3-4575-9801-1405F0AA2EA2) - Runtime: iOS 14.4 (18D46) - DeviceType: iPad Pro (9.7-inch)
Application Specific Backtrace 1:
0 CoreFoundation 0x00000001803f61fc __exceptionPreprocess + 236
1 libobjc.A.dylib 0x000000018016a438 objc_exception_throw + 56
2 CoreFoundation 0x00000001804053bc __CFExceptionProem + 0
3 CoreFoundation 0x00000001803fa45c ___forwarding___ + 1408
4 CoreFoundation 0x00000001803fc42c _CF_forwarding_prep_0 + 92
5 libswiftCoreLocation.dylib 0x00000001b1f98044 $s12CoreLocation39CLLocationCoordinate2DInNSValueObjCType33_25AD2332B1DC67E23B54508C4A7DAD45LLSPys4Int8VGvpfiAFyXEfU_ + 104
6 libswiftCoreLocation.dylib 0x00000001b1f97fcc globalinit_33_25AD2332B1DC67E23B54508C4A7DAD45_func0 + 12
7 libdispatch.dylib 0x0000000180100c48 _dispatch_client_callout + 16
8 libdispatch.dylib 0x0000000180102300 _dispatch_once_callout + 28
9 libswiftCore.dylib 0x000000018eed4ee8 swift_once + 44
10 libswiftCoreLocation.dylib 0x00000001b1f9817c $sSo22CLLocationCoordinate2DVs21_ObjectiveCBridgeable12CoreLocationsACP09_bridgeToC1C01_C5CTypeQzyFTW + 116
11 libswiftCore.dylib 0x000000018eeac510 _ZL37bridgeAnythingNonVerbatimToObjectiveCPN5swift11OpaqueValueEPKNS_14TargetMetadataINS_9InProcessEEEb + 360
12 libswiftCore.dylib 0x000000018ec10d70 $ss27_bridgeAnythingToObjectiveCyyXlxlF + 184
13 PlaygroundLogger 0x0000000100c6f9f8 globalinit_33_86996C1BC443F28F24E6A34F24210E4B_func8 + 2132
14 PlaygroundLogger 0x0000000100c6c848 globalinit_33_B1F54B50FE3698781248948D54A93147_func6 + 520
15 PlaygroundLogger 0x0000000100c6db44 playground_log_hidden + 276
16 ??? 0x0000000100c34350 0x0 + 4307764048
17 scratch-playground 0x0000000100ac2ea4 main + 0
18 CoreFoundation 0x0000000180365254 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 20
19 CoreFoundation 0x00000001803644ec __CFRunLoopDoBlocks + 404
20 CoreFoundation 0x000000018035eda8 __CFRunLoopRun + 780
21 CoreFoundation 0x000000018035e58c CFRunLoopRunSpecific + 572
22 GraphicsServices 0x000000018b9c2740 GSEventRunModal + 160
23 UIKitCore 0x00000001843ccbf0 -[UIApplication _run] + 964
24 UIKitCore 0x00000001843d19d0 UIApplicationMain + 112
25 scratch-playground 0x0000000100ac2f7c main + 216
26 libdyld.dylib 0x0000000180223cbc start + 4
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00000001bd7c3c10 __pthread_kill + 8
1 libsystem_pthread.dylib 0x00000001bd7fc034 pthread_kill + 260
2 libsystem_c.dylib 0x00000001800f378c abort + 100
3 libc++abi.dylib 0x000000018021cf20 abort_message + 128
4 libc++abi.dylib 0x000000018020ef1c demangling_terminate_handler() + 296
5 libobjc.A.dylib 0x000000018016a6e8 _objc_terminate() + 124
6 libc++abi.dylib 0x000000018021c3c0 std::__terminate(void (*)()) + 16
7 libc++abi.dylib 0x000000018021c358 std::terminate() + 44
8 libdispatch.dylib 0x0000000180100c5c _dispatch_client_callout + 36
9 libdispatch.dylib 0x0000000180102300 _dispatch_once_callout + 28
10 libswiftCore.dylib 0x000000018eed4ee8 swift_once + 44
11 libswiftCoreLocation.dylib 0x00000001b1f9817c protocol witness for _ObjectiveCBridgeable._bridgeToObjectiveC() in conformance CLLocationCoordinate2D + 116
12 libswiftCore.dylib 0x000000018eeac510 bridgeAnythingNonVerbatimToObjectiveC(swift::OpaqueValue*, swift::TargetMetadata<swift::InProcess> const*, bool) + 360
13 libswiftCore.dylib 0x000000018ec10d70 _bridgeAnythingToObjectiveC<A>(_:) + 184
14 com.apple.dt.PlaygroundLogger 0x0000000100c6f9f8 0x100c68000 + 31224
15 com.apple.dt.PlaygroundLogger 0x0000000100c6c848 0x100c68000 + 18504
16 com.apple.dt.PlaygroundLogger 0x0000000100c6db44 playground_log_hidden + 276
17 ??? 0x0000000100c34350 0 + 4307764048
18 com.apple.dt.playground.stub.iOS_Simulator.scratch-playground-10BCB7AC-7E28-4D75-BC98-3FA7A44E2F36 0x0000000100ac2ea4 linkResources + 328
19 com.apple.CoreFoundation 0x0000000180365254 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 20
20 com.apple.CoreFoundation 0x00000001803644ec __CFRunLoopDoBlocks + 404
21 com.apple.CoreFoundation 0x000000018035eda8 __CFRunLoopRun + 780
22 com.apple.CoreFoundation 0x000000018035e58c CFRunLoopRunSpecific + 572
23 com.apple.GraphicsServices 0x000000018b9c2740 GSEventRunModal + 160
24 com.apple.UIKitCore 0x00000001843ccbf0 -[UIApplication _run] + 964
25 com.apple.UIKitCore 0x00000001843d19d0 UIApplicationMain + 112
26 com.apple.dt.playground.stub.iOS_Simulator.scratch-playground-10BCB7AC-7E28-4D75-BC98-3FA7A44E2F36 0x0000000100ac2f7c main + 216
27 libdyld.dylib 0x0000000180223cbc start + 4
I think the problem is that there are two Core Location binaries in play:
0x18321e000 - 0x1832a8fff com.apple.corelocation (2420.12.16 - 2420.12.16) <F94D1F57-86D5-3A82-8F2B-80A9AEAC0308> /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreLocation.framework/CoreLocation
and
0x1b1f96000 - 0x1b1f98fff +libswiftCoreLocation.dylib (5) <EE615605-C11D-3F60-B611-8B1C1D45FEEA> /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/libswiftCoreLocation.dylib
and the playground is communicating from one world to the other world; talking to the iOS simulator. But there is an incompatibility between the two as the message is not carried across correctly due to type confusion. This leads to the
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSValue
valueWithMKCoordinate:]: unrecognized selector sent to class
0x1c9d3f588' terminating with uncaught exception of type NSException
I think you should file a bug with Apple. To avoid the problem, write your code based on the iOS Simulator directly, instead of using the Playground. In such circumstances, your code will execute correctly (since it directly will run against the simulator without the intervening bridge from the Playground).
As Alexander says in his comment, there is nothing wrong with the code you posted. The cause of the crash is elsewhere.

JSONDecoder crashing on TestFlight / AppStore

I am working on my Apple Watch app. Most of my components use JSON and use the Swift Codable protocol to decode JSON.
Now I wanted to prepare my release, but I received a message by a Beta tester that the App was always crashing on his Series 3.
After I installed the TestFlight build on my Series 3 I could reproduce the issue.
The crash logs from TestFlight and the crash logs extracted from my iPhone indicate that the crash is happening while the JSON gets decoded.
I have rather complex JSON structures, but I did not do any changes to them since the last update. Furthermore, decoding JSON works fine on Xcode builds (also on Series 3) and on newer Apple Watches (Series 4 + 5). I am struggling to find out what could cause the issue.
I discovered a post in the Apple developer forums with a similar issue, but without a solution to it: https://forums.developer.apple.com/thread/124627
Here's a part of the Stacktrace of my crash log:
Date/Time: 2020-02-05 08:37:42.9924 +0100
Launch Time: 2020-02-05 08:37:40.0000 +0100
OS Version: Watch OS 6.1.2 (17S5792a)
Release Type: User
Baseband Version: 4.40.02
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
Application Specific Information:
abort() called
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x4d9aefc8 __pthread_kill + 8
1 libsystem_pthread.dylib 0x4da260be pthread_kill + 108
2 libsystem_c.dylib 0x4d9383a4 abort + 84
3 libswiftCore.dylib 0x6cffbade swift_vasprintf+ 2341598 (char**, char const*, char*) + 0
4 libswiftCore.dylib 0x6d00932c swift::TargetMetadata<swift::InProcess>::getGenericArgs+ 2396972 () const + 0
5 libswiftCore.dylib 0x6d00508c _swift_initClassMetadataImpl+ 2379916 (swift::TargetClassMetadata<swift::InProcess>*, swift::ClassLayoutFlags, unsigned long, swift::TypeLayout const* const*, unsigned long*, bool) + 28
6 libswiftCore.dylib 0x6d005c86 swift_initClassMetadata2 + 22
7 libswiftCore.dylib 0x6cfdc6fc type metadata completion function for _KeyedDecodingContainerBox + 50
8 libswiftCore.dylib 0x6d00a6c2 swift::MetadataCacheEntryBase<(anonymous namespace)::GenericCacheEntry, void const*>::doInitialization+ 2401986 (swift::ConcurrencyControl&, swift::MetadataCompletionQueueEntry*, swift::MetadataRequest) + 178
9 libswiftCore.dylib 0x6d003a0c swift_getGenericMetadata + 1124
10 libswiftCore.dylib 0x6cdf4210 KeyedDecodingContainer.init<A>+ 213520 (_:) + 40
11 libswiftFoundation.dylib 0x6d156e0a __JSONDecoder.container<A>+ 323082 (keyedBy:) + 678
12 libswiftFoundation.dylib 0x6d1a3a1c protocol witness for Decoder.container<A>+ 637468 (keyedBy:) in conformance __JSONDecoder + 18
13 libswiftFoundation.dylib 0x6d1592b6 protocol witness for Decoder.container<A>+ 332470 (keyedBy:) in conformance __JSONDecoder + 32
14 libswiftCore.dylib 0x6cfdb1cc dispatch thunk of Decoder.container<A>+ 2208204 (keyedBy:) + 24
15 WatchSonos WatchKit Extension 0x00440bf2 0x358000 + 953330
16 WatchSonos WatchKit Extension 0x0043d08c 0x358000 + 938124
17 libswiftCore.dylib 0x6cfdb156 dispatch thunk of Decodable.init+ 2208086 (from:) + 12
18 libswiftFoundation.dylib 0x6d16fbee __JSONDecoder.unbox_+ 424942 (_:as:) + 4014
19 libswiftFoundation.dylib 0x6d156816 JSONDecoder.decode<A>+ 321558 (_:from:) + 642
20 libswiftFoundation.dylib 0x6d22af98 dispatch thunk of JSONDecoder.decode<A>+ 1191832 (_:from:) + 28
21 WatchSonos WatchKit Extension 0x0045db0c 0x358000 + 1071884
22 WatchSonos WatchKit Extension 0x00461cce 0x358000 + 1088718
23 WatchSonos WatchKit Extension 0x00461bde 0x358000 + 1088478
24 WatchSonos WatchKit Extension 0x00420ffa 0x358000 + 823290
25 WatchSonos WatchKit Extension 0x00425914 0x358000 + 842004
26 libdispatch.dylib 0x4d851846 _dispatch_call_block_and_release + 10
27 libdispatch.dylib 0x4d8528b8 _dispatch_client_callout + 6
28 libdispatch.dylib 0x4d85c6b0 _dispatch_main_queue_callback_4CF + 868
29 CoreFoundation 0x4dcdbbaa __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 10
30 CoreFoundation 0x4dcd7c00 __CFRunLoopRun + 1832
31 CoreFoundation 0x4dcd723a CFRunLoopRunSpecific + 370
32 GraphicsServices 0x50aebcd0 GSEventRunModal + 96
33 UIKitCore 0x65c91580 UIApplicationMain + 1730
34 libxpc.dylib 0x4da73c80 _xpc_objc_main.cold.3 + 152
35 libxpc.dylib 0x4da649b0 _xpc_objc_main + 184
36 libxpc.dylib 0x4da668c4 xpc_main + 110
37 Foundation 0x4e56b0c6 +[NSXPCListener serviceListener] + 0
38 PlugInKit 0x556d726c 0x556c5000 + 74348
39 WatchKit 0x5cfe9afe WKExtensionMain + 62
40 WatchKit 0x5d09f020 main + 10
Here's the position in the code that crashes:
required public init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
self.id = try values.decode(String.self, forKey: .id)
do {
if values.contains(.groups) {
let groups = try values.decode(Dictionary<String, SonosGroup>.self, forKey: .groups)
self.groups = groups
}
if values.contains(.players) {
let players = try values.decode(Array<SonosPlayer>.self, forKey: .players)
self.players = players
}
}catch let error {
print("Error decoding groups \(error)")
}
}
For me this looks like an Apple bug and I filed feedback for it, but this is no solution for the next release.
Does anyone know what's the difference between a TestFlight build and an Xcode release build?
I tried setting a different optimization level, disabling bitcode (not allowed for Apple Watch Apps) and I started replacing Codable with the good old JSONSerialization.
If anyone knows more about it, thank you for that.
Kind regards
Alex
I was having a very similar problem with Encodable and Decodable's in a swift package. Setting DEAD_CODE_STRIPPING = NO in my apps target fixed it. This seems to be a weird leftover of this bug:
https://bugs.swift.org/browse/SR-11564?focusedCommentId=51285&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-51285

Namespace SIGNAL, Code 0x5 with EXC_BREAKPOINT (SIGTRAP)

I am unable to reproduce the issue. One of my user sent the crash log and the issue seem to point to NSUserDefault setBool:forKey method.
Not working for user Device iPhone 6, iOS version: 12.4.4. For now only one user contacted due to the App crash.
Working on the devices I tested. (iPad Air 2, iPhone XS, iOS version 13.3)
This is the method I am using.
- (void) saveToDefaults:(NSString*)productId
{
[ [ NSUserDefaults standardUserDefaults ] setBool:YES forKey:productId ];
[ [ NSUserDefaults standardUserDefaults ] synchronize];
}
Crash dump
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x000000020eae32e4
Termination Signal: Trace/BPT trap: 5
Termination Reason: Namespace SIGNAL, Code 0x5
Terminating Process: exc handler [15897]
Triggered by Thread: 0
Thread 0 name:
Thread 0 Crashed:
0 CoreFoundation 0x000000020eae32e4 CFHash + 372 (CFRuntime.c:1147)
1 CoreFoundation 0x000000020eb75a38 CFBasicHashFindBucket + 224 (CFBasicHash.c:465)
2 CoreFoundation 0x000000020eb75a38 CFBasicHashFindBucket + 224 (CFBasicHash.c:465)
3 CoreFoundation 0x000000020eaada40 CFDictionaryGetValue + 120 (CFDictionary.c:413)
4 CoreFoundation 0x000000020eaca938 -[CFPrefsSearchListSource alreadylocked_setPrecopiedValues:forKeys:count:from:] + 496 (CFPrefsSearchListSource.m:632)
5 CoreFoundation 0x000000020eb81230 -[CFPrefsSource setValues:forKeys:count:copyValues:removeValuesForKeys:count:from:] + 372 (CFPrefsSource.m:742)
6 CoreFoundation 0x000000020eb81524 -[CFPrefsSource setValues:forKeys:count:copyValues:from:] + 36 (CFPrefsSource.m:766)
7 CoreFoundation 0x000000020ea3e3dc -[CFPrefsSource setValue:forKey:from:] + 64 (CFPrefsSource.m:772)
8 CoreFoundation 0x000000020eaccc54 __108-[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurat... + 272 (CFPrefsSearchListSource.m:1553)
9 CoreFoundation 0x000000020eacc698 normalizeQuintuplet + 340 (CFPrefsSearchListSource.m:63)
10 CoreFoundation 0x000000020ea3ad64 -[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurationUR... + 108 (CFPrefsSearchListSource.m:1433)
11 CoreFoundation 0x000000020ea3dd7c -[_CFXPreferences setValue:forKey:appIdentifier:container:configurationURL:] + 92 (CFXPreferences.m:759)
12 CoreFoundation 0x000000020eb8b360 _CFPreferencesSetAppValueWithContainerAndConfiguration + 132 (CFXPreferences.m:1867)
13 Foundation 0x000000020f4eb3b8 -[NSUserDefaults(NSUserDefaults) setObject:forKey:] + 64 (NSUserDefaults.m:228)
14 MyApp 0x00000001004adb14 -[IAPHelper saveToDefaults:] + 88 (IAPHelper.m:206)
15 MyApp 0x00000001004adc3c -[IAPHelper restoreTransaction:] + 224 (IAPHelper.m:223)
16 MyApp 0x00000001004ad928 -[IAPHelper paymentQueue:updatedTransactions:] + 264 (IAPHelper.m:0)
17 libdispatch.dylib 0x000000020e58ca38 _dispatch_call_block_and_release + 24 (init.c:1372)
18 libdispatch.dylib 0x000000020e58d7d4 _dispatch_client_callout + 16 (object.m:511)
19 libdispatch.dylib 0x000000020e53b008 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1068 (inline_internal.h:2441)
20 CoreFoundation 0x000000020eae0b20 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12 (CFRunLoop.c:1813)
21 CoreFoundation 0x000000020eadba58 __CFRunLoopRun + 1924 (CFRunLoop.c:3113)
22 CoreFoundation 0x000000020eadafb4 CFRunLoopRunSpecific + 436 (CFRunLoop.c:3247)
23 GraphicsServices 0x0000000210cdc79c GSEventRunModal + 104 (GSEvent.c:2245)
24 UIKitCore 0x000000023b33cc38 UIApplicationMain + 212 (UIApplication.m:4353)
25 MyApp 0x00000001004e9cec main + 88 (main.m:14)
26 libdyld.dylib 0x000000020e59e8e0 start + 4
How can I handle this exception to avoid this problem in the future.
Following up comments discussion and this answer indicating synchronize is not required (as per Apple's iOS 12 release notes):
My target iOS is from 11.2, guess I cannot use it for now.
Yes you can.
Wrapping up my suggestion in comment :
if (#available(iOS 12, *)) {
// don't need to synchronize
} else {
[NSUserDefaults.standardUserDefaults synchronize];
}
The above code #available Swift-like syntax assumes you're using Xcode 9 or higher. Which given the targeted iOS is pretty much a must.
Just to make myself 100% clear I cannot guarantee this will solve this particular crash issue, but it is worth trying as a very low effort fix candidate.

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?

iOS crash in CoreLocation

I'm seeing this crash my iOS app after it's been running for 10 minutes:
Date/Time: 2012-02-22 15:26:41.415 -0800
OS Version: iPhone OS 5.0.1 (9A405)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x49980286
Crashed Thread: 6
The offending thread:
Thread 6 name: Dispatch queue: com.apple.locationd.registration.xpcq
Thread 6 Crashed:
0 libstdc++.6.dylib 0x33ed32f8 std::string::compare(std::string const&) const + 8
1 CoreLocation 0x3095ad54 std::_Rb_tree<std::string, std::pair<std::string const, void ( block_pointer)(CLConnectionMessage*)>, std::_Select1st<std::pair<std::string const, void ( block_pointer)(CLConnectionMessage*)> >, std::less<std::string>, std::allocator<std::pair<std::string const, void ( block_pointer)(CLConnectionMessage*)> > >::find(std::string const&) + 32
2 CoreLocation 0x30959964 CLConnection::handleMessage(CLConnectionMessage*) + 16
3 CoreLocation 0x3095a78c __setEventHandler_block_invoke_0 + 360
4 libxpc.dylib 0x37a428c2 __XPC_CONNECTION_EVENT_HANDLER_CALLOUT__ + 30
5 libxpc.dylib 0x37a3bd5c _xpc_connection_recv_message + 500
6 libxpc.dylib 0x37a3bb18 _xpc_connection_wakeup_recv + 160
7 libxpc.dylib 0x37a3b9b8 _xpc_connection_wakeup2 + 1264
8 libxpc.dylib 0x37a3b3f6 _xpc_connection_wakeup + 62
9 libdispatch.dylib 0x36d7821e _dispatch_source_invoke + 510
10 libdispatch.dylib 0x36d75b70 _dispatch_queue_invoke$VARIANT$up + 40
11 libdispatch.dylib 0x36d75caa _dispatch_queue_drain + 202
12 libdispatch.dylib 0x36d75b66 _dispatch_queue_invoke$VARIANT$up + 30
13 libdispatch.dylib 0x36d75caa _dispatch_queue_drain + 202
14 libdispatch.dylib 0x36d75b66 _dispatch_queue_invoke$VARIANT$up + 30
15 libdispatch.dylib 0x36d75caa _dispatch_queue_drain + 202
16 libdispatch.dylib 0x36d75b66 _dispatch_queue_invoke$VARIANT$up + 30
17 libdispatch.dylib 0x36d7676c _dispatch_worker_thread2 + 208
18 libsystem_c.dylib 0x32ee21c8 _pthread_wqthread + 288
19 libsystem_c.dylib 0x32ee209c start_wqthread + 0
The console doesn't give me any messages except to say that I have a crash. Any thoughts?
So after lots of digging I was able to repro the issue and find what was causing it. This seems to occur if you call -[CLLocationManager startUpdatingLocation] and -[CLLocationManager stopUpdatingLocation] in a tight loop.
I was having this trouble as well, but only on iOS 5.x (testing in Simulator, don't have the device.) It seemed to occur when I had more than one location manager instance, and both had the delegate set.

Resources