问题
I've been getting this error in my app through Crashlytics. I can't find where and how this crash occurs. Here is the log from Crashlytics:
Thread : Crashed: com.apple.main-thread
0 CoreLocation 0x0000000183f62304 (null) + 60044
1 CoreLocation 0x0000000183f230f0 (null) + 1436
2 CoreLocation 0x0000000183f230f0 (null) + 1436
3 CoreLocation 0x0000000183f2261c (null) + 1980
4 CoreFoundation 0x0000000183754c9c __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 28
5 CoreFoundation 0x0000000183754940 __CFRunLoopDoTimer + 884
6 CoreFoundation 0x0000000183752054 __CFRunLoopRun + 1520
7 CoreFoundation 0x0000000183680dc0 CFRunLoopRunSpecific + 384
and this is also stated: Crashed: com.apple.main-thread EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x6136383561626000
Anyone can point me to the right direction? Thanks
回答1:
The timer needs to be invalidated when the app is becoming inactive. In the applicationWillResignActive method, invalidate the timer object. You can reset it back in the applicationDidBecomeActive method. From the docs:
You should use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. An application in the inactive state should do minimal work while it waits to transition to either the active or background state.
If you are building an app that needs to collect location in the background, ensure that you location updates background capabilities are utilised.
You can also try out the HyperTrack SDK for iOS which will set this up and more for you so that you can build your location feature and not worry about this grunt work. (Disclaimer: I work at HyperTrack.)
来源:https://stackoverflow.com/questions/32899583/ios-corelocation-null-crash