我想构建一个健身应用程序,将数据上传到HealthKit.有没有办法从另一个应用程序打开/导航到HealthKit?
Apple的健康数据是否有任何REST API支持?我知道healthkit api有助于从Apple健康数据存储发送和接收数据,但它非常受限于ios应用程序.
我想要实现的是利用来自任何其他平台的发送/接收,如网络/其他应用程序等,任何信息/解决方案赞赏.
这很少发生.这是堆栈跟踪的最后一行:
0 libdispatch.dylib 0x0000000197a85a9c dispatch_group_leave + 48
Run Code Online (Sandbox Code Playgroud)
dispatch_group_leave在一个完整的闭包中调用,它被调用如下:
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
{ () -> Void in
let query = HKStatisticsCollectionQuery(quantityType: quantityType,
quantitySamplePredicate: nil,
options: statisticOptions,
anchorDate: anchorDate,
intervalComponents: interval)
query.initialResultsHandler = {
complete()
Run Code Online (Sandbox Code Playgroud)
所以我们调度到后台线程,运行HKStatisticsCollectionQuery,然后调用一个名为complete的函数参数闭包.内部完成是调用dispatch_group_leave并发生崩溃的地方.
任何想法都非常感谢!谢谢!
我有一个watchOS 2应用程序,在运行期间显示健康数据.我使用HKWorkoutSession开始锻炼,如下所示:
self.workoutSession = HKWorkoutSession(activityType: .Running, locationType: .Outdoor)
self.workoutSession!.delegate = self;
self.healthStore.startWorkoutSession(self.workoutSession!)
Run Code Online (Sandbox Code Playgroud)
当屏幕关闭一段时间后,这会使我的应用程序保持在前台,用户稍后再次查看它.
现在让我们说在锻炼期间,用户切换到另一个应用程序或手表屏幕锁定(由于手表没有足够紧固),然后用户通过双击数字表冠重新启动我正在运行的应用程序.该应用程序从中断处继续恢复并继续按预期获取健康数据,但我的应用程序将不再保留在前台.锻炼仍在进行中,因为在表盘上我仍然可以看到顶部的锻炼图标,心率监测器继续收集心率数据,但应用程序拒绝留在前台.
有没有人知道如何在锻炼期间将锻炼应用程序恢复到前台,即使屏幕锁定或用户切换到其他应用程序?
我正在尝试使用heartRateVariabilitySDNN.我通过查询成功获取heartRate,并使用以下代码获取heartRateVariabilitySDNN但不知道它是如何工作的.此外,没有关于此查询或Apple示例代码的正确文档.
func createheartRateVariabilitySDNNStreamingQuery(_ workoutStartDate: Date) -> HKQuery? {
let typeHeart = HKQuantityType.quantityType(forIdentifier: .heartRateVariabilitySDNN)
let predicate: NSPredicate? = HKQuery.predicateForSamples(withStart: workoutStartDate, end: nil, options: HKQueryOptions.strictEndDate)
let squery = HKStatisticsQuery(quantityType: typeHeart!, quantitySamplePredicate: predicate, options: .discreteAverage, completionHandler: {(query: HKStatisticsQuery,result: HKStatistics?, error: Error?) -> Void in
DispatchQueue.main.async(execute: {() -> Void in
print("got: \(String(describing: result))")
})
})
return squery
}
Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中使用HealthKit.我从用户那里获得了访问HealthKit数据的权限.在授权之后,如果我检查特定HealthKit对象类型的授权状态,它总是返回拒绝访问.(1是枚举整数值).
这是我的代码
// Steps
if ([self.healthStore authorizationStatusForType:[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]] == HKAuthorizationStatusSharingAuthorized) {
[self accessStepsFrom:fromDate to:toDate];
}
//Sleep
if ([self.healthStore authorizationStatusForType:[HKObjectType categoryTypeForIdentifier:HKCategoryTypeIdentifierSleepAnalysis]] == HKAuthorizationStatusSharingAuthorized) {
[self accessSleepFrom:fromDate to:toDate];
}
//DOB
if ([self.healthStore authorizationStatusForType:[HKObjectType characteristicTypeForIdentifier:HKCharacteristicTypeIdentifierDateOfBirth]] == HKAuthorizationStatusSharingAuthorized) {
[self accessDOB];
}
Run Code Online (Sandbox Code Playgroud)
这种方法[self.healthStore authorizationStatusForType:[HKObjectType characteristicTypeForIdentifier:HKCharacteristicTypeIdentifierDateOfBirth]]总是让我失望1.需要帮助吗?
When trying to submit an app through Xcode or Application loader, with the "healthkit" entitlement enabled and a deployment target of 7.0, the app store gives the following error:
ERROR ITMS-9000: "This bundle is invalid. The key UIRequiredDeviceCapabilities contains value 'healthkit' which is incompatible with the MinimumOSVersion value of '7.0'."
The confusing thing is, both Strava and UP have healthkit enabled and iOS7 deployment targets. So it is technically possible to submit an app with these requirements.
Can someone please …
我有一个应用程序,其主要目的是将数据输入HealthKit.我想写一些Xcode UI测试来验证它是否成功编写了这些数据,但是我在Health应用程序中验证数据时遇到了一些困难.
当我最初录制我的测试时,它跳过我的模拟主页按钮按下,但它正在录制,当我滑到第一个主屏幕并导航到Health应用程序以显示数据点.
我搜索了如何按Home键,发现这个(有效):
XCUIDevice.shared.press(.home)
Run Code Online (Sandbox Code Playgroud)
但是,它记录的其他调用实际上都不适用于应用程序之外的导航.在主屏幕上滑动的录制代码显然看起来不对,当我tap()用a swipeRight()或者替换时也不起作用swipeLeft():
app.childrenMatchingType(.Window).elementBoundByIndex(1).childrenMatchingType(.Other).elementBoundByIndex(1).childrenMatchingType(.Other).element.childrenMatchingType(.Other).element.childrenMatchingType(.Other).elementBoundByIndex(0).childrenMatchingType(.ScrollView).element.tap()
Run Code Online (Sandbox Code Playgroud)
接下来几行,用于在主屏幕上启动应用程序,甚至不适用于当前可见页面上的应用程序图标:
let elementsQuery = app.scrollViews.otherElements
elementsQuery.icons["Health"].tap()
Run Code Online (Sandbox Code Playgroud)
有没有办法实现我正在尝试做的事情,或者我需要等待验证端到端测试,直到我添加从HealthKit读取到我的应用程序的能力?
基于WWDC 2015构建HealthKit/WatchKit应用程序- 会话203.
没有源代码所以我正在编写它.有一种方法我遇到困难,因为他们不讨论它.
幸运的是,addQuantitiesFromSamples对于将样本量添加到锻炼课程的所有锻炼类型,它都是相同的方法.
当然我有这个错误,因为我的代码中不存在该方法.
"HKQuantity"类型的值没有成员'addQuantitiesFromSamples'
我不知道如何编写一个添加样本量的方法.该方法必须相对基础,因为它正在项目中的所有三个示例查询中使用.
该sumDistanceSamples函数addQuantitiesFromSamples是调用神秘方法的地方.
这是包含相同错误的三个块之一,因此我只需要为其中一个找到解决方案.
WorkoutSessionManager.swift
class WorkoutSessionManager: NSObject, HKWorkoutSessionDelegate {
var activeEnergySamples: [HKQuantitySample] = []
var distanceSamples: [HKQuantitySample] = []
var heartRateSamples: [HKQuantitySample] = []
// ... code
var distanceType: HKQuantityType {
if self.workoutSession.activityType == .Cycling {
return HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDistanceCycling)!
} else {
return HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDistanceWalkingRunning)!
}
}
var currentActiveEnergyQuantity: HKQuantity
var currentDistanceQuantity: HKQuantity
var currentHeartRateSample: HKQuantitySample?
// ... code
// MARK: Data queries
// Create …Run Code Online (Sandbox Code Playgroud) Apple运行应用程序按日期提供数据,如下图所示.
通过使用HealthKit我从苹果健康获取步骤数据
let p1 = HKQuery.predicateForSamples(withStart: fromDate, end: Date(), options: .strictStartDate)
let p2 = HKQuery.predicateForObjects(withMetadataKey: HKMetadataKeyWasUserEntered, operatorType: .notEqualTo, value: true)
let timeSortDesriptor = NSSortDescriptor(key: HKSampleSortIdentifierEndDate, ascending: false)//as in health kit entry
let quantityType = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.stepCount)!
let predicate = HKQuery.predicateForSamples(withStart: fromDate, end: Date(), options: .strictStartDate)
let sourceQuery = HKSourceQuery(sampleType: quantityType, samplePredicate: predicate, completionHandler: { query,sources,error in
if sources?.count != 0 && sources != nil {
let lastIndex = sources!.count - 1
var sourcesArray = Array(sources!)
for i in …Run Code Online (Sandbox Code Playgroud)