From a859c28398ea17f9026de7528d1f7d8396f55e23 Mon Sep 17 00:00:00 2001 From: Matas Date: Tue, 14 Feb 2023 12:25:06 +0200 Subject: [PATCH] fix(ios): make query timeout after 30s --- ios/RNHealthTracker.swift | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/ios/RNHealthTracker.swift b/ios/RNHealthTracker.swift index 881f119..1496d56 100644 --- a/ios/RNHealthTracker.swift +++ b/ios/RNHealthTracker.swift @@ -13,6 +13,7 @@ import HealthKit @objc(RNHealthTracker) class RNHealthTracker: NSObject { private let healthStore: HKHealthStore = HKHealthStore() + private let QUERY_TIMEOUT_IN_SECONDS = 30.0 @objc static func requiresMainQueueSetup() -> Bool { return true @@ -286,7 +287,7 @@ class RNHealthTracker: NSObject { healthStore.execute(query) - DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) { + DispatchQueue.main.asyncAfter(deadline: .now() + QUERY_TIMEOUT_IN_SECONDS) { self.healthStore.stop(query) } } @@ -344,7 +345,7 @@ class RNHealthTracker: NSObject { healthStore.execute(query) - DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) { + DispatchQueue.main.asyncAfter(deadline: .now() + QUERY_TIMEOUT_IN_SECONDS) { self.healthStore.stop(query) } } @@ -404,7 +405,7 @@ class RNHealthTracker: NSObject { healthStore.execute(query) - DispatchQueue.main.asyncAfter(deadline: .now() + 20) { + DispatchQueue.main.asyncAfter(deadline: .now() + QUERY_TIMEOUT_IN_SECONDS) { self.healthStore.stop(query) } } @@ -471,7 +472,7 @@ class RNHealthTracker: NSObject { healthStore.execute(query) - DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) { + DispatchQueue.main.asyncAfter(deadline: .now() + QUERY_TIMEOUT_IN_SECONDS) { self.healthStore.stop(query) } } @@ -535,7 +536,7 @@ class RNHealthTracker: NSObject { healthStore.execute(query) - DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) { + DispatchQueue.main.asyncAfter(deadline: .now() + QUERY_TIMEOUT_IN_SECONDS) { self.healthStore.stop(query) } } @@ -680,6 +681,10 @@ class RNHealthTracker: NSObject { ) else { return } healthStore.execute(sampleQuery) + + DispatchQueue.main.asyncAfter(deadline: .now() + QUERY_TIMEOUT_IN_SECONDS) { + self.healthStore.stop(sampleQuery) + } } @objc public func getLatestDataRecord( @@ -864,7 +869,7 @@ class RNHealthTracker: NSObject { healthStore.execute(query) - DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) { + DispatchQueue.main.asyncAfter(deadline: .now() + QUERY_TIMEOUT_IN_SECONDS) { self.healthStore.stop(query) } } @@ -941,7 +946,7 @@ class RNHealthTracker: NSObject { healthStore.execute(query) - DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) { + DispatchQueue.main.asyncAfter(deadline: .now() + QUERY_TIMEOUT_IN_SECONDS) { self.healthStore.stop(query) } }