Close Menu
geekfence.comgeekfence.com
    What's Hot

    Melinda Gates’ venture firm backs Magnify Ventures’ $46.6M Fund II

    July 2, 2026

    Indosat outlines AI Grid vision as 5G modernization targets nationwide AI-ready network

    July 2, 2026

    Context Window Management for Long-Running Agents: Strategies and Tradeoffs

    July 2, 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 Read0 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

    Installing simulator runtimes from the command line – Donny Wals

    June 29, 2026

    SwiftText Learns to Write | Cocoanetics

    June 28, 2026

    uitabbarcontroller – UITabBar unselectedItemTintColor ignored iOS 26

    June 27, 2026

    Responses Bug in LM Studio

    June 23, 2026

    ios – How to make headerView with overlapping content design in SwiftUI

    June 22, 2026

    Kits All the Way Down

    June 18, 2026
    Top Posts

    Understanding U-Net Architecture in Deep Learning

    November 25, 202558 Views

    Hard-braking events as indicators of road segment crash risk

    January 14, 202630 Views

    Redefining AI efficiency with extreme compression

    March 25, 202628 Views
    Don't Miss

    Melinda Gates’ venture firm backs Magnify Ventures’ $46.6M Fund II

    July 2, 2026

    Early-stage firm Magnify Ventures has raised $46.6 million for its second fund from LPs, including…

    Indosat outlines AI Grid vision as 5G modernization targets nationwide AI-ready network

    July 2, 2026

    Context Window Management for Long-Running Agents: Strategies and Tradeoffs

    July 2, 2026

    Run log analytics for a fraction of the cost with the new engine for Amazon OpenSearch Service

    July 2, 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

    Melinda Gates’ venture firm backs Magnify Ventures’ $46.6M Fund II

    July 2, 2026

    Indosat outlines AI Grid vision as 5G modernization targets nationwide AI-ready network

    July 2, 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.