Strange crash in core location in iOS 12 version - ios

There is a strange crash happening in my code related to core location. Tried a lot but Was not able to figure out the reason for the crash.
Here is the stack race of the crash report :-
com.apple.main-thread
0 libsystem_kernel.dylib 0x1f0f53ed0 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x1f0f533a8 mach_msg + 72
2 libxpc.dylib 0x1f102d0c0 xpc_pipe_routine + 388
3 libxpc.dylib 0x1f1012db8 _xpc_interface_routine + 204
4 libxpc.dylib 0x1f1013394 _xpc_look_up_endpoint + 224
5 libxpc.dylib 0x1f1019870 _xpc_connection_bootstrap_look_up_slow + 212
6 libxpc.dylib 0x1f101be64 _xpc_connection_init + 540
7 libxpc.dylib 0x1f101aae8 _xpc_connection_activate_if_needed + 100
8 libxpc.dylib 0x1f101ab7c xpc_connection_resume + 88
9 CoreLocation 0x1f82c9fa4 CLClientCreateIso6709Notation + 45656
10 CoreLocation 0x1f82cbfc8 CLClientCreateIso6709Notation + 53884
11 CoreLocation 0x1f828395c CLClientStopVehicleHeadingUpdates + 32296
12 Quickride 0x104a76964 LocationChangeListener.startLocationListener() (LocationChangeListener.swift:124)
13 Quickride 0x104f8cb0c BaseLiveRideMapViewController.viewWillAppear(_:) (BaseLiveRideMapViewController.swift)
14 Quickride 0x104f8cc40 #objc BaseLiveRideMapViewController.viewWillAppear(_:) (BaseLiveRideMapViewController.swift)
15 UIKitCore 0x21de8b8ec -[UIViewController _setViewAppearState:isAnimating:] + 584
16 UIKitCore 0x21de8bfd0 -[UIViewController __viewWillAppear:] + 140
17 UIKitCore 0x21ddf2dfc -[UINavigationController _startTransition:fromViewController:toViewController:] + 892
18 UIKitCore 0x21ddf3abc -[UINavigationController _startDeferredTransitionIfNeeded:] + 1184
19 UIKitCore 0x21ddf4dbc -[UINavigationController __viewWillLayoutSubviews] + 164
20 UIKitCore 0x21ddd6fac -[UILayoutContainerView layoutSubviews] + 224
21 UIKitCore 0x21e8f2ea4 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1380
22 QuartzCore 0x1f59bac70 -[CALayer layoutSublayers] + 184
23 QuartzCore 0x1f59bfc00 CA::Layer::layout_if_needed(CA::Transaction*) + 324
24 QuartzCore 0x1f591e718 CA::Context::commit_transaction(CA::Transaction*) + 340
25 QuartzCore 0x1f594d04c CA::Transaction::commit() + 608
26 QuartzCore 0x1f594deb4 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 92
27 CoreFoundation 0x1f13577a8 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
28 CoreFoundation 0x1f135243c __CFRunLoopDoObservers + 412
29 CoreFoundation 0x1f13529dc __CFRunLoopRun + 1264
30 CoreFoundation 0x1f13521cc CFRunLoopRunSpecific + 436
31 GraphicsServices 0x1f35c9584 GSEventRunModal + 100
32 UIKitCore 0x21e44d054 UIApplicationMain + 212
33 Quickride 0x1049b168c main (AppDelegate.swift:29)
34 libdyld.dylib 0x1f0e12bb4 start + 4
The code where the crash is happening is :-
func startLocationListener(){
AppDelegate.getAppDelegate().log.debug("startLocationListener()")
let ridePreferences = UserDataCache.getInstance()?.getLoggedInUserRidePreferences()
if ridePreferences?.locationUpdateAccuracy == 0{
return
}
UIDevice.current.isBatteryMonitoringEnabled = true
if UIDevice.current.batteryLevel > 0 && UIDevice.current.batteryLevel < 0.15{
AppDelegate.getAppDelegate().log.debug("Battery level is less so not starting location updates")
return
}
self.locationManager = CLLocationManager()
locationManager!.requestWhenInUseAuthorization()
self.locationManager!.desiredAccuracy = kCLLocationAccuracyBestForNavigation
if #available(iOS 9.0, *) {
self.locationManager!.allowsBackgroundLocationUpdates = true
}
if ridePreferences?.locationUpdateAccuracy == 1{
self.locationManager!.distanceFilter = Double(AppConfiguration.MIN_DISTANCE_CHANGE_FOR_UPDATES_MEDIUM)
}else if ridePreferences?.locationUpdateAccuracy == 2{
self.locationManager!.distanceFilter = Double(AppConfiguration.MIN_DISTANCE_CHANGE_FOR_UPDATES_HIGH)
}
self.locationManager!.desiredAccuracy = kCLLocationAccuracyBestForNavigation
self.locationManager!.pausesLocationUpdatesAutomatically = true
self.locationManager!.activityType = CLActivityType.automotiveNavigation
self.locationManager!.delegate = self
self.locationManager!.startUpdatingLocation()
let appDelegate : AppDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.startLocationManager()
locationUpdateToServerTask = UserLocationUpdateToServerTask()
if locationManager?.location != nil{
locationUpdateToServerTask?.setLatestLocation(newLocation: (locationManager?.location)!)
processLocationUpdate(location: (locationManager?.location)!)
}
The crash is happening in this line as per the crashlytics report :-
self.locationManager!.pausesLocationUpdatesAutomatically = true
Can some one help me out ? Thanks in advance

Related

React native iOS Application crashing with code:0x8BADF00D explanation:scene-update

I'm working on developing an application that requires the use of Mapbox turn-by-turn navigation. I've had to create a custom react native module to help me achieve this, but I think somewhere along my implementation is causing some issues pushing the phone to overheat and eventually crash.
Here's my crash report:
Exception Type: EXC_CRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Termination Reason: FRONTBOARD; [2343432205]
<RBSTerminateContext| domain:10 code:0x8BADF00D explanation:scene-update watchdog transgression: application<org.name.appName>:27065 exhausted real (wall clock) time allowance of 10.00 seconds
ProcessVisibility: Foreground
ProcessState: Running
WatchdogEvent: scene-update
WatchdogVisibility: Background
WatchdogCPUStatistics: (
"Elapsed total CPU time (seconds): 40.290 (user 19.790, system 20.500), 67% CPU",
"Elapsed application CPU time (seconds): 1.558, 3% CPU"
) reportType:CrashLog maxTerminationResistance:Interactive>
Triggered by Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x1b7fd9f90 __psynch_cvwait + 8
1 libsystem_pthread.dylib 0x1f1c9e254 _pthread_cond_wait + 1228
2 libc++.1.dylib 0x199207ddc std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 28
3 libc++.1.dylib 0x199208984 std::__1::__assoc_sub_state::__sub_wait(std::__1::unique_lock<std::__1::mutex>&) + 56
4 libc++.1.dylib 0x1992088d4 std::__1::__assoc_sub_state::copy() + 56
5 libc++.1.dylib 0x199208c18 std::__1::future<void>::get() + 32
6 Mapbox 0x10532a3e0 0x1052e8000 + 271328
7 Mapbox 0x1056ac72c 0x1052e8000 + 3950380
8 CoreFoundation 0x1808aef88 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 28
9 CoreFoundation 0x18094ac3c ___CFXRegistrationPost_block_invoke + 52
10 CoreFoundation 0x18091dff4 _CFXRegistrationPost + 456
11 CoreFoundation 0x1808c4df4 _CFXNotificationPost + 716
12 Foundation 0x1820c3f58 -[NSNotificationCenter postNotificationName:object:userInfo:] + 96
13 UIKitCore 0x182f93aec __47-[UIApplication _applicationDidEnterBackground]_block_invoke + 316
14 UIKitCore 0x182ef2ecc +[UIViewController _performWithoutDeferringTransitionsAllowingAnimation:actions:] + 164
15 UIKitCore 0x18312bdcc -[UIApplication _applicationDidEnterBackground] + 144
16 UIKitCore 0x182f21278 __101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke_2 + 840
17 UIKitCore 0x182edbaf0 _UIScenePerformActionsWithLifecycleActionMask + 104
18 UIKitCore 0x183007438 __101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke + 224
19 UIKitCore 0x183128104 -[_UISceneLifecycleMultiplexer _performBlock:withApplicationOfDeactivationReasons:fromReasons:] + 248
20 UIKitCore 0x1833692f8 -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:] + 760
21 UIKitCore 0x1832f4818 -[_UISceneLifecycleMultiplexer uiScene:transitionedFromState:withTransitionContext:] + 340
22 UIKitCore 0x182edc8f4 __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke + 196
23 UIKitCore 0x182f9d160 +[BSAnimationSettings(UIKit) tryAnimatingWithSettings:actions:completion:] + 892
24 UIKitCore 0x182ede804 _UISceneSettingsDiffActionPerformChangesWithTransitionContext + 276
25 UIKitCore 0x182fc9448 -[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:] + 384
26 UIKitCore 0x1834515cc __64-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke.613 + 776
27 UIKitCore 0x182f0d13c -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 256
28 UIKitCore 0x182f50a50 -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 288
29 UIKitCore 0x182eda834 -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 492
30 FrontBoardServices 0x192567b30 -[FBSScene updater:didUpdateSettings:withDiff:transitionContext:completion:] + 528
31 FrontBoardServices 0x19258077c __94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke_2 + 152
32 FrontBoardServices 0x19256506c -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 240
33 FrontBoardServices 0x19256b540 __94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke + 396
34 libdispatch.dylib 0x18058f670 _dispatch_client_callout + 20
35 libdispatch.dylib 0x180593128 _dispatch_block_invoke_direct + 264
36 FrontBoardServices 0x1925669c4 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 48
37 FrontBoardServices 0x192565d8c -[FBSSerialQueue _targetQueue_performNextIfPossible] + 220
38 FrontBoardServices 0x19256a414 -[FBSSerialQueue _performNextFromRunLoopSource] + 28
39 CoreFoundation 0x18093f0d0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
40 CoreFoundation 0x18094fd90 __CFRunLoopDoSource0 + 208
41 CoreFoundation 0x18088a104 __CFRunLoopDoSources0 + 376
42 CoreFoundation 0x18088f8a4 __CFRunLoopRun + 820
43 CoreFoundation 0x1808a3468 CFRunLoopRunSpecific + 600
44 GraphicsServices 0x19c44738c GSEventRunModal + 164
45 UIKitCore 0x1832465d0 -[UIApplication _run] + 1100
46 UIKitCore 0x182fc4f74 UIApplicationMain + 364
47 appName 0x104368880 0x104364000 + 18560
48 dyld 0x104f19aa4 start + 520
And here's my code:
#objc func tappedButton(sender: UIButton) {
guard let routeResponse = routeResponse, let navigationRouteOptions = routeOptions else { return }
let parentVC = self.parentViewController
let navigationOptions = NavigationOptions(simulationMode: .never)
let navigationViewController = NavigationViewController(for: routeResponse, routeIndex: 0,
routeOptions: navigationRouteOptions, navigationOptions: navigationOptions)
navigationViewController.delegate = self
parentVC!.addChild(navigationViewController)
self.addSubview(navigationViewController.view)
navigationViewController.view.frame = self.bounds
navigationViewController.didMove(toParent: parentVC)
self.navigationViewController = navigationViewController
}
I needed to add the child this way with to get it to work with react native since I can't create the native module as a UIViewController with the main app being a UIViewController.
I added this to create a parentVC:
extension UIView {
var parentViewController: UIViewController? {
var parentResponder: UIResponder? = self
while parentResponder != nil {
parentResponder = parentResponder!.next
if let viewController = parentResponder as? UIViewController {
return viewController
}
}
return nil
}
}
Any help would be greatly appreciated!

coder.decodeDouble causing crashes on app updates, value was previously an optional

I have an object that stores latitude and longitude coordinates. At one point, they were stored as an Optional Double?. I have since changed so it is a non optional Double. Now I see random crash logs from what I assume is users updating their app.
I tried checking to make sure that there is a value there, but it is still causing the crash.
let lat: Double
...
required init (coder aDecoder: NSCoder) {
...
if aDecoder.containsValue(forKey: "lat") {
lat = aDecoder.decodeDouble(forKey: "lat") //here is the crash
}else{
lat = 0
}
...
}
I previously came across this issue and used the following code to get around it, but Xcode says I cannot decode Doubles from objects any more
if let v = aDecoder.decodeObject(forKey: "lat") as? Double{//*** -[NSKeyedUnarchiver decodeObjectForKey:] : value for key ( lat ) is not an object. This will become an error in the future.
lat = v
}else{
if aDecoder.containsValue(forKey: "lat") {
lat = aDecoder.decodeDouble(forKey: "lat")
}else{
lat = 0
}
}
Here is a crash log:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x18120004c __exceptionPreprocess + 220 (NSException.m:200)
1 libobjc.A.dylib 0x199874f54 objc_exception_throw + 60 (objc-exception.mm:565)
2 Foundation 0x182aa8e68 -[NSCoder __failWithException:] + 180 (NSCoder.m:0)
3 Foundation 0x182aa8fd4 -[NSCoder(Exceptions) __failWithExceptionName:errorCode:format:] + 260 (NSCoder.m:1191)
4 Foundation 0x182a4689c _decodeDouble + 660 (NSKeyedArchiver.m:0)
5 Foundation 0x1829bd3cc -[NSKeyedUnarchiver decodeDoubleForKey:] + 172 (NSKeyedArchiver.m:3918)
6 *Project* 0x102eefb98 specialized Location.init(coder:) + 1936 (Location.swift:145)
7 *Project* 0x102eed854 init + 4 (<compiler-generated>:0)
8 *Project* 0x102eed854 #objc Location.init(coder:) + 32
9 Foundation 0x1829c0268 _decodeObjectBinary + 2560 (NSKeyedArchiver.m:3058)
10 Foundation 0x1829a4a78 _decodeObject + 180 (NSKeyedArchiver.m:3324)
11 Foundation 0x1829c4304 -[NSKeyedUnarchiver decodeObjectForKey:] + 176 (NSKeyedArchiver.m:3344)
12 Foundation 0x182a272b8 +[NSKeyedUnarchiver unarchiveObjectWithData:] + 84 (NSKeyedArchiver.m:2390)
13 *Project* 0x102ee729c APS.loadOnDeckFromiCloud() + 240 (APS.swift:138)
14 *Project* 0x102ee7058 APS.().init() + 860 (APS.swift:105)
15 *Project* 0x102ee6ce8 one-time initialization function for SI + 40 (APS.swift:0)
16 libdispatch.dylib 0x180e72660 _dispatch_client_callout + 20 (object.m:560)
17 libdispatch.dylib 0x180e73f08 _dispatch_once_callout + 32 (once.c:52)
18 *Project* 0x102f3417c specialized DivertToOnboardingIfNeeded_VC.viewWillAppear(_:) + 1536 (APS.swift:97)
19 *Project* 0x102f334a8 viewWillAppear + 4 (<compiler-generated>:0)
20 *Project* 0x102f334a8 #objc DivertToOnboardingIfNeeded_VC.viewWillAppear(_:) + 28
21 UIKitCore 0x1837ba3e0 -[UIViewController _setViewAppearState:isAnimating:] + 664 (UIViewController.m:5522)
22 UIKitCore 0x1838e9004 -[UIViewController __viewWillAppear:] + 120 (UIViewController.m:5654)
23 UIKitCore 0x1838ba5b0 -[UINavigationController _startTransition:fromViewController:toViewController:] + 720 (UINavigationController.m:7329)
24 UIKitCore 0x183ae657c -[UINavigationController _startDeferredTransitionIfNeeded:] + 876 (UINavigationController.m:7494)
25 UIKitCore 0x1839bb6ac -[UINavigationController __viewWillLayoutSubviews] + 168 (UINavigationController.m:7806)
26 UIKitCore 0x1838e20f4 -[UILayoutContainerView layoutSubviews] + 228 (UILayoutContainerView.m:88)
27 UIKitCore 0x18379aed8 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2620 (UIView.m:18347)
28 QuartzCore 0x184ef6e24 CA::Layer::layout_if_needed(CA::Transaction*) + 536 (CALayer.mm:10038)
29 QuartzCore 0x184ee9644 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 144 (CALayer.mm:2480)
30 QuartzCore 0x184efdc6c CA::Context::commit_transaction(CA::Transaction*, double, double*) + 524 (CAContextInternal.mm:2586)
31 QuartzCore 0x184f06560 CA::Transaction::commit() + 680 (CATransactionInternal.mm:449)
32 UIKitCore 0x183963f9c __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 44 (UIApplication.m:11470)
33 CoreFoundation 0x1811d9924 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 28 (CFRunLoop.c:1820)
34 CoreFoundation 0x1811da820 __CFRunLoopDoBlocks + 412 (CFRunLoop.c:1862)
35 CoreFoundation 0x181172808 __CFRunLoopRun + 840 (CFRunLoop.c:2953)
36 CoreFoundation 0x1811863b8 CFRunLoopRunSpecific + 600 (CFRunLoop.c:3268)
37 GraphicsServices 0x19cb1638c GSEventRunModal + 164 (GSEvent.c:2200)
38 UIKitCore 0x183b266a8 -[UIApplication _run] + 1100 (UIApplication.m:3493)
39 UIKitCore 0x1838a57f4 UIApplicationMain + 2092 (UIApplication.m:5046)
40 *Project* 0x102e93388 main + 68 (MapBox_VC.swift:15)
41 dyld 0x103169a24 start + 520 (dyldMain.cpp:876)
How do I check the value stored in lat to make sure it is a Double ? (Non optional)

Understanding Firebase Crashlytics report for iOS app

I have an iOS app that uses Firebase Crashlytics for reporting crashes. Now I have a report for a crash but my problem is that I could not understand what exactly caused the crash from this report.
Crashlytics report:
Crashed: com.apple.main-thread
0 Nail it 0x104db77a8 CaseDetailsViewController.getbaseData() + 253
(CaseDetailsViewController.swift:253)
1 Nail it 0x104db5168 CaseDetailsViewController.viewDidLoad() + 4335047016 (<compiler-generated>:4335047016)
2 Nail it 0x104db521c #objc CaseDetailsViewController.viewDidLoad() + 4335047196 (<compiler-generated>:4335047196)
3 UIKitCore 0x185d11658 -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 100
4 UIKitCore 0x185d160e8 -[UIViewController loadViewIfRequired] + 936
5 UIKitCore 0x185d164f0 -[UIViewController view] + 28
6 UIKit 0x1b913374c -[UIViewControllerAccessibility dismissViewControllerWithTransition:completion:] + 268
7 UIKitCore 0x185d28d6c -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 508
8 UIKitCore 0x185d2b474 -[UIViewController dismissViewControllerAnimated:completion:] + 132
9 UIKit 0x1b91333c0 -[UIViewControllerAccessibility dismissViewControllerAnimated:completion:] + 120
10 Nail it 0x104db98ec #objc CaseDetailsViewController.backButton(_:) + 4335065324 (<compiler-generated>:4335065324)
11 UIKitCore 0x18635a72c -[UIApplication sendAction:to:from:forEvent:] + 96
12 UIKitCore 0x185a05474 __45-[_UIButtonBarTargetAction _invoke:forEvent:]_block_invoke + 80
13 UIKitCore 0x185a05304 -[_UIButtonBarTargetAction _invoke:forEvent:] + 236
14 UIKitCore 0x18635a72c -[UIApplication sendAction:to:from:forEvent:] + 96
15 UIKitCore 0x185d6aed0 -[UIControl sendAction:to:forEvent:] + 240
16 UIKitCore 0x185d6b228 -[UIControl _sendActionsForEvents:withEvent:] + 396
17 UIKitCore 0x185d6a24c -[UIControl touchesEnded:withEvent:] + 516
18 UIKitCore 0x18639449c -[UIWindow _sendTouchesForEvent:] + 1280
19 UIKitCore 0x186395c64 -[UIWindow sendEvent:] + 3468
20 UIKitCore 0x1863718ec -[UIApplication sendEvent:] + 344
21 UIKit 0x1b90db80c -[UIApplicationAccessibility sendEvent:] + 96
22 UIKitCore 0x1863f2970 __dispatchPreprocessedEventFromEventQueue + 6808
23 UIKitCore 0x1863f54ec __handleEventQueueInternal + 5364
24 UIKitCore 0x1863ed168 __handleHIDEventFetcherDrain + 140
25 CoreFoundation 0x182223ad8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
26 CoreFoundation 0x182223a30 __CFRunLoopDoSource0 + 80
27 CoreFoundation 0x1822231b8 __CFRunLoopDoSources0 + 184
28 CoreFoundation 0x18221e1e8 __CFRunLoopRun + 788
29 CoreFoundation 0x18221dba8 CFRunLoopRunSpecific + 424
30 GraphicsServices 0x18c394344 GSEventRunModal + 160
31 UIKitCore 0x1863593e4 UIApplicationMain + 1932
32 Nail it 0x104d797cc main + 16 (AppDelegate.swift:16)
33 libdyld.dylib 0x1820a58f0 start + 4
Below is the function getBaseData() from CasesDetails View Controller:
func getbaseData(){
let userDefaults = UserDefaults.standard
mobile = userDefaults.value(forKey: "mobile") as! String
altenativeMobile = userDefaults.string(forKey: "altenativeMobile") ?? mobile
privateKey = userDefaults.value(forKey: "privateKey") as! String
////reading JSON
let categoriesJsonString = userDefaults.value(forKey: "categoriesString") as! String
let data = categoriesJsonString.data(using: .utf8)!
if let json = try? JSON(data: data) {
let arrayCats = json["content"][1]["caseMappings"][caseCategoryGlobal].array
if(isNoSubsGlob == 0){
if let arrayCatsCount = arrayCats?.count {
print("The array has been created with \(arrayCatsCount) element")
print("sub1Glob= \(sub1Glob) & sub2Glob= \(sub2Glob)")
for var i in 0..<arrayCatsCount{
let sub1 = json["content"][1]["caseMappings"][caseCategoryGlobal][i]["sub1"].string!
let sub2 = json["content"][1]["caseMappings"][caseCategoryGlobal][i]["sub2"].string ?? ""
if (sub1 == sub1Glob && sub2 == sub2Glob){
departmentId = json["content"][1]["caseMappings"][caseCategoryGlobal][i]["departmentId"].int!
WorkTypeId = json["content"][1]["caseMappings"][caseCategoryGlobal][i]["categoryId"].int!
issueCode = json["content"][1]["caseMappings"][caseCategoryGlobal][i]["id"].int!
}
}
}
}else{
departmentId = json["content"][1]["caseMappings"][caseCategoryGlobal][0]["departmentId"].int!
WorkTypeId = json["content"][1]["caseMappings"][caseCategoryGlobal][0]["categoryId"].int!
issueCode = json["content"][1]["caseMappings"][caseCategoryGlobal][0]["id"].int!
}
}
contactNumberText.text = altenativeMobile
}
and the line 235 is (contactNumberText.text = altenativeMobile) as the last line in the code above
All UI stuff should be performed on main thread, that is what your crash report shows (crash due to main thread.)
So your last line should be :
DispatchQueue.main.async {
self.contactNumberText.text = altenativeMobile
}
Update this line, your crash will fixed.

CIFilter with CIQRCodeGenerator cause crash

I'm trying to generate QR code with following code :
DispatchQueue.main.async {
let image = generateQRCode(from: qrCodeString)
}
func generateQRCode(from string: String?) -> UIImage? {
if let data = string?.data(using: .utf8, allowLossyConversion: false) {
if let filter = CIFilter(name: "CIQRCodeGenerator") {
filter.setValue(data, forKey: "inputMessage")
let transform = CGAffineTransform(scaleX: 5, y: 5)
if let output = filter.outputImage?.transformed(by: transform) {
return UIImage(ciImage: output)
}
}
}
return nil
}
This code works well for most devices/iOS version.
But firebase brings me a lot of device crashes: iPhone 11, XR. iOS 13.4.0
Crashed: com.apple.main-thread
0 CocoaDebug 0x1023a0adc perform_rebinding_with_section + 332
1 CocoaDebug 0x1023a087c rebind_symbols_for_image + 416
2 libdyld.dylib 0x1999c3f4c invocation function for block in dyld3::AllImages::runImageCallbacks(dyld3::Array<dyld3::LoadedImage> const&) + 244
3 libdyld.dylib 0x1999c3768 dyld3::AllImages::runImageCallbacks(dyld3::Array<dyld3::LoadedImage> const&) + 160
4 libdyld.dylib 0x1999c8dd8 dyld3::AllImages::loadImage(Diagnostics&, unsigned int, dyld3::closure::DlopenClosure const*, bool, bool, bool, bool) + 580
5 libdyld.dylib 0x1999c89ec dyld3::AllImages::dlopen(Diagnostics&, char const*, bool, bool, bool, bool, bool, void const*) + 868
6 libdyld.dylib 0x1999ca434 dyld3::dlopen_internal(char const*, int, void*) + 364
7 libdyld.dylib 0x1999bd6c0 dlopen + 116
8 CoreFoundation 0x199bcf5c8 _CFBundleDlfcnLoadBundle + 156
9 CoreFoundation 0x199af1eac _CFBundleLoadExecutableAndReturnError + 372
10 Foundation 0x199ec27a8 -[NSBundle loadAndReturnError:] + 316
11 CoreImage 0x19b479bcc invocation function for block in register_more_builtins(void (NSString*) block_pointer) + 804
12 libdispatch.dylib 0x19986833c _dispatch_client_callout + 20
13 libdispatch.dylib 0x199869a68 _dispatch_once_callout + 32
14 CoreImage 0x19b476318 register_more_builtins(void (NSString*) block_pointer) + 304
15 CoreImage 0x19b476b40 classNameIsSystemFilter(NSString*) + 112
16 CoreImage 0x19b476dbc +[CIFilter(CIFilterRegistryPrivate) filterWithName:setDefaults:] + 396
17 MYApp 0x100656598 QRCodeViewController.generateQRCode(from:) + 4370490776 (<compiler-generated>:4370490776)
18 MYApp 0x1006563a4 QRCodeViewController.viewDidLoad() + 28 (QRCodeViewController.swift:28)
19 MYApp 0x10065642c #objc QRCodeViewController.viewDidLoad() + 4370490412 (<compiler-generated>:4370490412)
20 UIKitCore 0x19d6a236c -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 104
21 UIKitCore 0x19d6a6f20 -[UIViewController loadViewIfRequired] + 952
22 UIKitCore 0x19d6a730c -[UIViewController view] + 32
23 UIKitCore 0x19d602fa4 -[UINavigationController _startCustomTransition:] + 1148
24 UIKitCore 0x19d617478 -[UINavigationController _startDeferredTransitionIfNeeded:] + 692
25 UIKitCore 0x19d618818 -[UINavigationController __viewWillLayoutSubviews] + 176
26 UIKitCore 0x19d5fb4fc -[UILayoutContainerView layoutSubviews] + 228
27 UIKitCore 0x19e1de6a0 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2168
28 QuartzCore 0x1a08314a0 -[CALayer layoutSublayers] + 292
29 QuartzCore 0x1a08318e0 CA::Layer::layout_if_needed(CA::Transaction*) + 472
30 QuartzCore 0x1a0843dc4 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 144
31 QuartzCore 0x1a0788884 CA::Context::commit_transaction(CA::Transaction*, double) + 304
32 QuartzCore 0x1a07b33d0 CA::Transaction::commit() + 656
33 QuartzCore 0x1a07b3fc8 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 96
34 CoreFoundation 0x199b42c54 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 36
35 CoreFoundation 0x199b3d8e4 __CFRunLoopDoObservers + 420
36 CoreFoundation 0x199b3dd84 __CFRunLoopRun + 1020
37 CoreFoundation 0x199b3d660 CFRunLoopRunSpecific + 480
38 GraphicsServices 0x1a3f4e604 GSEventRunModal + 164
39 UIKitCore 0x19dd1215c UIApplicationMain + 1944
40 MYApp 0x100518e54 main + 4369190484 (<compiler-generated>:4369190484)
41 libdyld.dylib 0x1999b91ec start + 4
I tried several different encoding, I tried to do it on the main thread or in backgroud, but always without result.
it looks like the whole class CIFilter causes a crash !!
I figured out how to fix it. The problem was the third-party CocoaDebug ! I remove the pod and I have no more crashes! Thanks!

Crashlytics Crash report around Maps SDK, gmscore::renderer::GLState::Flush()

Our app has quite a lot of crashes happening to users, reported by crashlytics, however we are unable to reproduce it on our end. Here is the full crash report:
Crashed: com.apple.main-thread
0 TheBarCode 0x100ccc2d8 gmscore::renderer::GLState::Flush() + 16388
1 TheBarCode 0x100cd7630 gmscore::renderer::GLScopedContext::~GLScopedContext() + 31600
2 TheBarCode 0x100d3a314 -[GMSEntityRendererView setFrame:] + 436308
3 TheBarCode 0x100d82578 -[GMSVectorMapView setFrame:] + 184912
4 UIKitCore 0x18f6af878 -[UIView(Geometry) _applyAutoresizingMaskWithOldSuperviewSize:] + 576
5 UIKitCore 0x18f6b0510 -[UIView(Geometry) _resizeWithOldSuperviewSize:] + 236
6 CoreFoundation 0x18b18195c __NSARRAY_IS_CALLING_OUT_TO_A_BLOCK__ + 16
7 CoreFoundation 0x18b084fb0 -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 416
8 UIKitCore 0x18f6af5e4 -[UIView(Geometry) resizeSubviewsWithOldSize:] + 156
9 UIKitCore 0x18f6b082c -[UIView(Geometry) setBounds:] + 688
10 UIKitCore 0x18f6b00e0 -[UIView(Geometry) _applyISEngineLayoutValuesToBoundsOnly:] + 528
11 UIKitCore 0x18f6b04ac -[UIView(Geometry) _resizeWithOldSuperviewSize:] + 136
12 CoreFoundation 0x18b18195c __NSARRAY_IS_CALLING_OUT_TO_A_BLOCK__ + 16
13 CoreFoundation 0x18b084fb0 -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 416
14 UIKitCore 0x18f6af5e4 -[UIView(Geometry) resizeSubviewsWithOldSize:] + 156
15 UIKitCore 0x18f5f76fc -[UIView(AdditionalLayoutSupport) _is_layout] + 148
16 UIKitCore 0x18f6b7090 -[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 1032
17 Gradientable 0x101738798 UIView.swizzled_layoutSubviews() + 50 (Gradientable.swift:50)
18 Gradientable 0x1017388d0 #objc UIView.swizzled_layoutSubviews() + 4359784656 (<compiler-generated>:4359784656)
19 UIKitCore 0x18f6ca17c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2140
20 QuartzCore 0x191c322c0 -[CALayer layoutSublayers] + 284
21 QuartzCore 0x191c3843c CA::Layer::layout_if_needed(CA::Transaction*) + 480
22 QuartzCore 0x191c43140 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 136
23 QuartzCore 0x191b8b884 CA::Context::commit_transaction(CA::Transaction*, double) + 304
24 QuartzCore 0x191bb5574 CA::Transaction::commit() + 676
25 QuartzCore 0x191bb5f68 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 92
26 CoreFoundation 0x18b12be68 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
27 CoreFoundation 0x18b126d54 __CFRunLoopDoObservers + 416
28 CoreFoundation 0x18b127320 __CFRunLoopRun + 1308
29 CoreFoundation 0x18b126adc CFRunLoopRunSpecific + 464
30 GraphicsServices 0x1950c7328 GSEventRunModal + 104
31 UIKitCore 0x18f23463c UIApplicationMain + 1936
32 TheBarCode 0x10082756c main + 21 (Preference.swift:21)
33 libdyld.dylib 0x18afb0360 start + 4
The other strange thing is that we are not receiving any additional added (on which screen does it happen) logs along with the crash.
Additional Information:
Recently we have upgraded our application for iOS 13 and xcode 11. By doing so, we have also updated google maps iOS SDK to 3.8.0. After upgrading we are receiving crash reports. On the previously used version we never experienced this crash i.e. 2.7.0
In our application we have multiple instances of GMSMapView i.e. around 8 instances embedded in a UIPageViewController. For the sake of memory management we only keep the visible version of GMSMapView and discard other instances in viewDidDisappear method of view controller. Here is the code that we are using to setup map and clearing map.
func setupMapView() {
let mapView = GMSMapView(frame: CGRect.zero)
mapView.settings.allowScrollGesturesDuringRotateOrZoom = false
if CLLocationManager.authorizationStatus() != .notDetermined {
mapView.settings.myLocationButton = false
mapView.isMyLocationEnabled = true
self.myLocationButtonContainer.isHidden = false
} else {
self.myLocationButtonContainer.isHidden = true
}
self.mapContainer.insertSubview(mapView, at: 0)
mapView.autoPinEdgesToSuperviewEdges()
let iconGenerator = GMUCustomClusterIconGenerator()
let algorithm = GMUNonHierarchicalDistanceBasedAlgorithm()
let renderer = GMUDefaultClusterRenderer(mapView: mapView, clusterIconGenerator: iconGenerator)
renderer.delegate = self
self.clusterManager = GMUClusterManager(map: mapView, algorithm: algorithm, renderer: renderer)
self.clusterManager?.setDelegate(self, mapDelegate: self)
self.mapView = mapView
self.setUpMarkers()
self.restoreMapCameraPosition(animated: false)
}
func clearMapView() {
self.clusterManager?.clearItems()
self.mapView?.clear()
self.mapView?.removeFromSuperview()
self.mapView = nil
self.clusterManager = nil
}
Screenshots from crashlytics:
Screenshot from the data tab of crashlytics:
Just downgrade to 3.7.0 iOS Maps SDK.
pod 'GoogleMaps', '~> 3.7.0'

Resources