99% UICollectionView CPU Utilization - Significant Location Change Not Calling & ldquo; didUpdateLocations & rdquo;

advertisements

What works is that the app gets launched into background on significant location change. In AppDelegate I check for the UIApplicationLaunchOptionsLocationKey and init a location manager:

locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters
locationManager.distanceFilter = 50
locationManager.allowsBackgroundLocationUpdates = true
locationManager.startMonitoringSignificantLocationChanges()

The initial view controller is a UITabBarController which shows a UICollectionViewController.

When I set that there are no cells in the UICollectionView everything works fine and didUpdateLocations of the locationManager gets called.

However when the UICollectionView's numberOfItemsInSection returns 1, the didUpdateLocations does not get called. Instead the UICollectionView has 99% CPU usage for minutes until the app crashes.

I deleted all controls and all code from the cell, so it is an empty cell now, and still this happens.

In Time Profiler I see that is has something to do with UICollectionViewData setLayoutAttributes.

What's wrong here?

Update 1: There is the stack under setLayoutAttributes.

Update 2: The app works fine and never crashed when launched normally by the user.


You understand the code better than anybody on this site, but this looks suspicious:

You are running some kind of loop over Observers, whatever those are. It looks like on each one it is doing a callback, and that is doing some kind of transaction that needs a commit, and as part of the commit it is displaying something, and as part of that it is doing a bunch of layout, of subviews and so on. That's basically sopping up all of the time.

You might want to turn off the display updating until you're done.