Giter Site home page Giter Site logo

[Question] iOS 12 about locokit HOT 6 CLOSED

sobri909 avatar sobri909 commented on August 29, 2024
[Question] iOS 12

from locokit.

Comments (6)

sobri909 avatar sobri909 commented on August 29, 2024

Unfortunately with our existing build on the latest released version of LocoKit, we're experiencing weird/inaccurate location data on iOS 12.

Hmm. Can you confirm whether it was the LocoKit version change, or the iOS version change that caused the differences in location data accuracy?

Basically what I've been seeing is some devices are affected by a weird "sleepwalking" effect on iOS 12, where the provided locations have horizontalAccuracy values that are orders of magnitude apart from their real accuracy levels. For example locations with horizontalAccuracy of 30 metres, but with a coordinate that's 300 metres away from the real location (and often even a kilometre or more away from the real location).

So for those affected devices, the phone effectively sleepwalks, being convinced it's going to a leisurely stroll around the neighbourhood, with high accuracy.

I've only seen it on two of my test devices so far. My main phone is the most affected, and sleepwalks almost every night. Another test device exhibits the problem about once a week. And the other test devices are unaffected. (All test devices currently are on either iOS 12.0, 12.0.1, or 12.1). The problem started with the early iOS 12 betas, and appears to remain in the iOS 12.1 betas (although I haven't done extensive testing on iOS 12.1 yet).

For what it's worth, I'm also experiencing quite a few crashes in the background on TimelineStore.save(). The app crashes after some time in the background. Anything potentially wrong with my setup or are you noticing the same thing?

from locokit.

sobri909 avatar sobri909 commented on August 29, 2024

Ugh. I tapped the post button by accident. Let me continue that reply...

For what it's worth, I'm also experiencing quite a few crashes in the background on TimelineStore.save(). The app crashes after some time in the background. Anything potentially wrong with my setup or are you noticing the same thing?

I haven't seen that in the LocoKit Demo App at all. However I have seen it in Arc App. Arc App does a lot of fiddling with the database outside of LocoKit's managed save methods, so it risks upsetting the foreign keys in some cases. But that shouldn't be possible in plain LocoKit, as long as the timeline items aren't being manipulated and saved outside of the processing queue.

To deal with the crashes in Arc App I've been using a bit of a hack, in my TimelineStore subclass.

    override func save() {
        var savingItems: Set<TimelineItem> = []
        var savingSamples: Set<PersistentSample> = []

        mutex.sync {
            savingItems = itemsToSave.filter { $0.needsSave }
            itemsToSave.removeAll(keepingCapacity: true)

            savingSamples = samplesToSave.filter { $0.needsSave }
            samplesToSave.removeAll(keepingCapacity: true)
        }

        if !savingItems.isEmpty {
            do {
                try pool.write { db in
                    let now = Date()
                    for case let item as TimelineObject in savingItems {
                        item.transactionDate = now
                        do { try item.save(in: db) }
                        catch PersistenceError.recordNotFound { os_log("PersistenceError.recordNotFound", type: .error) }
                        catch let error as DatabaseError where error.resultCode == .SQLITE_CONSTRAINT {
                            logToFile("ERROR: \(error)")

                            Crashlytics.sharedInstance().recordError(error, withAdditionalUserInfo:
                                ["extendedResultCode": String(describing: error.extendedResultCode)])

                            // break the edges and put it back in the queue
                            logToFile("BREAKING ITEM EDGES")
                            (item as? ArcItem)?.previousItemId = nil
                            (item as? ArcItem)?.nextItemId = nil
                            save(item, immediate: false)
                            
                        } catch {
                            logToFile("ERROR: \(error)")
                            Crashlytics.sharedInstance().recordError(error)
                            save(item, immediate: false)
                        }
                    }
                    db.afterNextTransactionCommit { db in
                        for case let item as TimelineObject in savingItems where !item.hasChanges {
                            item.lastSaved = item.transactionDate
                        }
                    }
                }

            } catch {
                logToFile("ERROR: \(error)")
                Crashlytics.sharedInstance().recordError(error)
            }
        }

        if !savingSamples.isEmpty {
            do {
                try pool.write { db in
                    let now = Date()
                    for case let sample as TimelineObject in savingSamples {
                        sample.transactionDate = now
                        do { try sample.save(in: db) }
                        catch PersistenceError.recordNotFound { os_log("PersistenceError.recordNotFound", type: .error) }
                        catch {
                            logToFile("ERROR: \(error)")
                            Crashlytics.sharedInstance().recordError(error)
                            save(sample, immediate: false)
                        }
                    }
                    db.afterNextTransactionCommit { db in
                        for case let sample as TimelineObject in savingSamples where !sample.hasChanges {
                            sample.lastSaved = sample.transactionDate
                        }
                    }
                }

            } catch {
                logToFile("ERROR: \(error)")
                Crashlytics.sharedInstance().recordError(error)
            }
        }
    }

That shouldn't be necessary in plain LocoKit, but it sounds like you're perhaps running into a similar situation as Arc's, so it's worth giving that a try.

from locokit.

sobri909 avatar sobri909 commented on August 29, 2024

I'll do some more testing with the LocoKit Demo App, to see if I can reproduce the crashes in that. And will either look into moving some portion of my hack upstream into LocoKit, or refactoring the transactions to be more foreign key safe.

It'll definitely be worth having a look at the specific SQLite error codes though, to see whether it's really a constraint failure error, or something else.

from locokit.

sobri909 avatar sobri909 commented on August 29, 2024

Oh, for the iOS 12 sleepwalking location data, that's definitely not Arc / LocoKit specific, on my test devices. Once the phone is sleepwalking, the same drifting data is visible in Apple Maps, Google Maps, etc. You can see the location drift across the neighbourhood, with a small accuracy radius, showing that the phone is convinced it's going for a lovely stroll when really it's sitting on a table 😏

from locokit.

joediv avatar joediv commented on August 29, 2024

Well, the issue was on my end πŸ€¦β€β™‚οΈ . I enabled data protection and the device would crash when attempting to write to SQLite in the background. Missed that the first time around, my bad. Still going to add that bit of code from Arc to avoid crashes.

Looks like we're getting sleepwalking location data on one device at least. 🀞Apple figures something out soon. Thanks for all the help

from locokit.

sobri909 avatar sobri909 commented on August 29, 2024

Aah, yeah, data protection would do that πŸ˜‚ I got excited about turning that on in Arc, until I realised it was completely impossible to use.

Looks like we're getting sleepwalking location data on one device at least. 🀞Apple figures something out soon.

Yeah, fingers crossed. Still no sign of improvement in iOS 12.0.1 or 12.1 though, which is concerning. It's probably worth filing a Radar for it, although I only ever do that in the most extreme cases, because it's such a disheartening experience.

If Apple don't solve it, I'm planning an ML based approach of auto detecting the bogus data and automatically flagging it. But it will require user input to train the ML model. So in Arc's case, it will train the model each time the user marks a segment with the "This location data is bogus" feature.

But I hope it doesn't come to needing something like that.

from locokit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.