Close Menu
geekfence.comgeekfence.com
    What's Hot

    Arcee, a US open source AI lab, says Chinese models are not inherently dangerous

    July 22, 2026

    AT&T braces for the agentic AI wave

    July 22, 2026

    The Current State of Agentic AI

    July 22, 2026
    Facebook X (Twitter) Instagram
    • About Us
    • Contact Us
    Facebook Instagram
    geekfence.comgeekfence.com
    • Home
    • UK Tech News
    • AI
    • Big Data
    • Cyber Security
      • Cloud Computing
      • iOS Development
    • IoT
    • Mobile
    • Software
      • Software Development
      • Software Engineering
    • Technology
      • Green Technology
      • Nanotechnology
    • Telecom
    geekfence.comgeekfence.com
    Home»iOS Development»ios – HKStatisticsCollectionQuery initialResultsHandler returns nil results for one specific user — read auth granted, data exists, survives reinstall
    iOS Development

    ios – HKStatisticsCollectionQuery initialResultsHandler returns nil results for one specific user — read auth granted, data exists, survives reinstall

    AdminBy AdminJuly 2, 2026No Comments2 Mins Read4 Views
    Facebook Twitter Pinterest LinkedIn Telegram Tumblr Email
    ios – HKStatisticsCollectionQuery initialResultsHandler returns nil results for one specific user — read auth granted, data exists, survives reinstall
    Share
    Facebook Twitter LinkedIn Pinterest Email


    Environment: iPhone 13 Pro, iOS 26.5. Affects a single user out of many; cannot reproduce on any of our test devices.

    We use HKStatisticsCollectionQuery to read step counts for a statistics screen. For one specific user, the query’s initialResultsHandler appears to deliver results == nil (the success branch never runs), so our completion is never called and the screen shows an infinite spinner.

    func getDayHourlySteps(currentDay: Date, completion: @escaping ([HKStatistics]) -> Void) {
        let anchorComponents = Calendar.current.dateComponents([.day, .month, .year, .hour], from: currentDay)
        let anchorDate = Calendar.current.date(from: anchorComponents)!
        var interval = DateComponents(); interval.hour = 1
    
        let manualPredicate = NSPredicate(format: "metadata.%K != YES", HKMetadataKeyWasUserEntered)
    
        let query = HKStatisticsCollectionQuery(
            quantityType: HKQuantityType.quantityType(forIdentifier: .stepCount)!,
            quantitySamplePredicate: manualPredicate,
            options: .cumulativeSum,
            anchorDate: anchorDate,
            intervalComponents: interval
        )
        query.initialResultsHandler = { _, results, error in
            guard let results else {
                // For the affected user we suspect we land here (results == nil).
                // What HKError shows up here? (we are adding logging now)
                return
            }
            // ...enumerate & completion...
        }
        healthStore.execute(query)
    }
    

    What we’ve confirmed / ruled out:

    • Read authorization for stepCount is granted (the user toggled it ON in the HealthKit sheet on video).

    • The Apple Health app shows step data for this user (so data exists).

    • A coarser query (2-year interval) for the same user succeeds, while the hourly query appears to fail — same type / predicate / options / auth.

    • Symptom persists across app reinstall and device reboot, and re-granting Health permission.

    • Permission denial returns empty results (per Apple docs), not an error — so this isn’t simple denial.

    • Not errorDatabaseInaccessible as far as we can tell (foreground, device unlocked).

    Questions:

    1. What can cause HKStatisticsCollectionQuery.initialResultsHandler to return results == nil (with an error) persistently for one device/account, when read auth is granted and data exists?

    2. Can errorHealthDataRestricted occur without an MDM/supervised profile (i.e., on a normal consumer device)? What device/account states actually trigger it?

    3. Is it expected that a coarse-interval query succeeds while an hourly-interval query on the same type fails for the same user?

    We’re adding logging of the actual HKError code + authorizationStatus for the next occurrence, but would appreciate any insight on what conditions produce this.



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email

    Related Posts

    ios – How to resolve the “Failed to build cache” build error in Xcode on macOS running in Docker in the docurr/macos project?

    July 22, 2026

    ios – Do Critical Alert (Apple) sounds play one at a time, or can two overlap?

    July 17, 2026

    ios – Bizarre animation issue in SwiftUI

    July 12, 2026

    security – How and where mnemonic/private keys are generated/stored in IOS for mobile non-custodial wallet

    July 7, 2026

    JSON All the Way Down

    July 3, 2026

    Installing simulator runtimes from the command line – Donny Wals

    June 29, 2026
    Top Posts

    Understanding U-Net Architecture in Deep Learning

    November 25, 202562 Views

    Hard-braking events as indicators of road segment crash risk

    January 14, 202631 Views

    Redefining AI efficiency with extreme compression

    March 25, 202630 Views
    Don't Miss

    Arcee, a US open source AI lab, says Chinese models are not inherently dangerous

    July 22, 2026

    As Chinese open-weight AI models grow in capability and popularity, arguments about what should be…

    AT&T braces for the agentic AI wave

    July 22, 2026

    The Current State of Agentic AI

    July 22, 2026

    The last mile: why great first-party data still doesn’t make great marketing

    July 22, 2026
    Stay In Touch
    • Facebook
    • Instagram
    About Us

    At GeekFence, we are a team of tech-enthusiasts, industry watchers and content creators who believe that technology isn’t just about gadgets—it’s about how innovation transforms our lives, work and society. We’ve come together to build a place where readers, thinkers and industry insiders can converge to explore what’s next in tech.

    Our Picks

    Arcee, a US open source AI lab, says Chinese models are not inherently dangerous

    July 22, 2026

    AT&T braces for the agentic AI wave

    July 22, 2026

    Subscribe to Updates

    Please enable JavaScript in your browser to complete this form.
    Loading
    • About Us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • Terms and Conditions
    © 2026 Geekfence.All Rigt Reserved.

    Type above and press Enter to search. Press Esc to cancel.