mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-11-28 16:58:41 +01:00
fix(ios): HealthKit session timestamp fallback, bg-delivery entitlement, guard fixes
- HealthKitHeartRate.swift workoutBuilder(_:didCollectDataOf:): fall back to
Date() when mostRecentQuantityDateInterval() is nil for the SESSION path
only, instead of dropping the sample — live session samples aren't
batched, so receipt time is a faithful fallback (the spec's sample-time
rule exists for batched passive delivery).
- authorize(): the `guard let self else { return }` in the requestAuthorization
completion never called `result`, leaving the Dart side hanging; now
resolves with "unknown".
- beginCollection completion: widen the guard so any `!ok` (not just
`!ok && error != nil`) falls back to passive.
- Runner.entitlements: add com.apple.developer.healthkit.background-delivery,
required for enableBackgroundDelivery on the passive path.
- STORE_METADATA.md: "iOS 7.0+" read as an iOS version; reworded to
"BikeControl 7.0+ on iOS".
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -147,4 +147,4 @@ within the `prop` submodule, then bump the pointer here.
|
||||
|
||||
## App Privacy
|
||||
|
||||
- iOS 7.0+: **Health & Fitness → Health** is read (heart rate) for app functionality only; not linked to identity, not used for tracking. Declared because of the Apple Health heart-rate source (HealthKit entitlement).
|
||||
- BikeControl 7.0+ on iOS: **Health & Fitness → Health** is read (heart rate) for app functionality only; not linked to identity, not used for tracking. Declared because of the Apple Health heart-rate source (HealthKit entitlement).
|
||||
|
||||
@@ -66,7 +66,7 @@ final class HealthKitHeartRate: NSObject, FlutterStreamHandler {
|
||||
}
|
||||
let workoutType = HKObjectType.workoutType()
|
||||
store.requestAuthorization(toShare: [workoutType], read: [heartRateType]) { [weak self] _, error in
|
||||
guard let self else { return }
|
||||
guard let self else { return result("unknown") }
|
||||
if let error {
|
||||
return result(FlutterError(code: "authorize", message: error.localizedDescription, details: nil))
|
||||
}
|
||||
@@ -163,13 +163,13 @@ final class HealthKitHeartRate: NSObject, FlutterStreamHandler {
|
||||
let now = Date()
|
||||
session.startActivity(with: now)
|
||||
builder.beginCollection(withStart: now) { [weak self] ok, error in
|
||||
guard let error, !ok else { return }
|
||||
guard !ok else { return }
|
||||
// beginCollection's completion runs off-main; hop before touching
|
||||
// sessionBox, and re-check identity — a stop()+start() in between
|
||||
// may already have replaced this session with a newer one.
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
guard let self, session === (self.sessionBox as AnyObject?) else { return }
|
||||
self.fallBackToPassive(from: session, builder: builder, reason: error.localizedDescription)
|
||||
self.fallBackToPassive(from: session, builder: builder, reason: error?.localizedDescription ?? "beginCollection failed")
|
||||
}
|
||||
}
|
||||
return true
|
||||
@@ -225,9 +225,12 @@ extension HealthKitHeartRate: HKLiveWorkoutBuilderDelegate {
|
||||
func workoutBuilder(_ workoutBuilder: HKLiveWorkoutBuilder, didCollectDataOf collectedTypes: Set<HKSampleType>) {
|
||||
guard collectedTypes.contains(heartRateType),
|
||||
let statistics = workoutBuilder.statistics(for: heartRateType),
|
||||
let latest = statistics.mostRecentQuantity(),
|
||||
let interval = statistics.mostRecentQuantityDateInterval() else { return }
|
||||
emitSample(latest, at: interval.start, mode: "session")
|
||||
let latest = statistics.mostRecentQuantity() else { return }
|
||||
// Live session samples are not batched, so receipt time is a faithful
|
||||
// fallback here (the spec's sample-time rule exists for batched passive
|
||||
// delivery) — a missing interval must not drop the sample.
|
||||
let at = statistics.mostRecentQuantityDateInterval()?.start ?? Date()
|
||||
emitSample(latest, at: at, mode: "session")
|
||||
}
|
||||
|
||||
func workoutBuilderDidCollectEvent(_ workoutBuilder: HKLiveWorkoutBuilder) {}
|
||||
|
||||
@@ -22,5 +22,7 @@
|
||||
<true/>
|
||||
<key>com.apple.developer.healthkit.access</key>
|
||||
<array/>
|
||||
<key>com.apple.developer.healthkit.background-delivery</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
Reference in New Issue
Block a user