- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 Apple Watch 复杂功能中显示用户的每日步数。我通过调用 HKHealthStore 的 requestAuthorizationToShareTypes 方法来设置我的类,并且该复杂功能在首次添加到表盘时会正确显示步骤。但是,在进行健康工具包查询时,刷新永远不会成功。我怀疑这与 HealthKit 权限有关,因为没有调用 HKSampleQuery 的完成处理程序。如果我只是注释掉健康工具包查询,那么我的代码会按预期刷新。有谁知道我可能会错过什么?或者并发症后台刷新不允许访问HealthKit?
这是有效的代码块:
/// Provide the entry that should currently be displayed.
/// If you pass back nil, we will conclude you have no content loaded and will stop talking to you until you next call -reloadTimelineForComplication:.
func getCurrentTimelineEntryForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTimelineEntry?) -> Void) {
let calendar = NSCalendar.currentCalendar()
let now = NSDate()
var startDate: NSDate? = nil
var interval: NSTimeInterval = 0
let endDate = NSDate()
calendar.rangeOfUnit(NSCalendarUnit.Day, startDate: &startDate, interval: &interval, forDate: now)
// Show dummy step data...
let timelineEntry = self.buildTimelineEntry(complication, stepCount: 10, currentDateInterval: NSDate())
handler(timelineEntry)
}
这是不起作用的代码块。错误情况下的更新甚至没有被调用:
/// Provide the entry that should currently be displayed.
/// If you pass back nil, we will conclude you have no content loaded and will stop talking to you until you next call -reloadTimelineForComplication:.
func getCurrentTimelineEntryForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTimelineEntry?) -> Void) {
let calendar = NSCalendar.currentCalendar()
let now = NSDate()
var startDate: NSDate? = nil
var interval: NSTimeInterval = 0
let endDate = NSDate()
calendar.rangeOfUnit(NSCalendarUnit.Day, startDate: &startDate, interval: &interval, forDate: now)
let predicate = HKQuery.predicateForSamplesWithStartDate(startDate, endDate: endDate, options: HKQueryOptions.StrictStartDate)
let sortDescriptor = NSSortDescriptor(key:HKSampleSortIdentifierStartDate, ascending: true)
let stepSampleType = HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierStepCount)!
let sampleQuery = HKSampleQuery(sampleType: stepSampleType, predicate: predicate, limit: 0, sortDescriptors: [sortDescriptor]) { (sampleQuery, results, error ) -> Void in
if error != nil {
dispatch_async(dispatch_get_main_queue(), { () -> Void in
let timelineEntry = self.buildTimelineEntry(complication, stepCount: 10, currentDateInterval: NSDate())
handler(timelineEntry)
})
return
}
self.currentSteps = [HKQuantitySample]()
if results != nil {
self.currentSteps = results as! [HKQuantitySample]
}
let countUnit = HKUnit(fromString: "count")
var stepCount = 0.0
var currentDate = now
for result in self.currentSteps {
stepCount += result.quantity.doubleValueForUnit(countUnit)
currentDate = result.endDate
}
dispatch_async(dispatch_get_main_queue(), { () -> Void in
let timelineEntry = self.buildTimelineEntry(complication, stepCount: stepCount, currentDateInterval: currentDate)
handler(timelineEntry)
})
}
self.healthStore.executeQuery(sampleQuery)
}
最佳答案
尝试在并发症 Controller 中异步获取 (HealthKit) 数据是不可靠的。
此外,尝试在并发症 Controller 内获取或计算将不必要地用完分配给您的并发症的执行时间预算。
Apple recommends在复杂数据源需要之前获取数据并缓存它。
The job of your data source class is to provide ClockKit with any requested data as quickly as possible. The implementations of your data source methods should be minimal. Do not use your data source methods to fetch data from the network, compute values, or do anything that might delay the delivery of that data. If you need to fetch or compute the data for your complication, do it in your iOS app or in other parts of your WatchKit extension, and cache the data in a place where your complication data source can access it. The only thing your data source methods should do is take the cached data and put it into the format that ClockKit requires.
关于watchos-2 - 使用 HealthKit 查询时,Apple Watch 并发症不会在后台刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34569001/
在我们准备发布之前,我们的离岸开发人员不小心将一个发布分支 merge 到了 master 中。这让我们没有主分支,也没有能力发布修补程序。我试图用 rebase 来解决这个问题,但不太明白发生了什么
这个很复杂,不一定是一个问题。如果有任何可能的帮助,我将不胜感激。 我读过可以在没有服务器访问权限的情况下使用 websockets,但我似乎找不到任何示例来说明它是如何实现的。基于以下两点,我得出了
问候, 我有一个 php 站点,从年初开始运行良好。然后为 IE8 发布了一个补丁,导致我必须运行的 CSS 出现故障。 这是已知问题还是孤立问题? 我的主要问题源于试图将标题锁定到位,同时允许主体滚
我们一直在努力获取git-subtree在一个项目上工作(使用 git 版本 1.7.9.4)并且遇到了一些复杂情况。几个月前,其他人使用此命令添加了子树: git subtree add --pre
我在让并发症发挥作用时遇到了问题。如果我能够可靠地刷新它们将会很有帮助。 因此我将强制按下菜单按钮链接到以下方法 @IBAction func updateComplication() { l
我试了好几个小时。我有一个线程更改了我的 UI 的 JTextField,这完全破坏了 UI。线程(我们称之为线程 A)由 ActionListener 生成。 .setText() 函数调用在线程
我有一个 SQLite 数据库,它显示在我的 C# Windows 窗体的数据 GridView 中。所以,这个数据库有四列。我特别感兴趣的只是其中一个专栏。该列指示消息的类型。它可以是错误、警报或初
我正在尝试使用通过 WatchConnectivity 从 IOS/iPhone 传输的数据更新 watchOS2 时钟套件并发症。 尽管进行了相当多的研究,但迄今为止未成功。我发现虽然其他帖子描述了
我一直在为我的应用程序开发 watchOS 2 复杂功能。它看起来很棒...除了我想调整的最后一件事。 Complication 模板提供的文本对齐方式似乎不是我想要的。为了这个问题的目的,让我们使用
我正在开发一款带有模块化大脸复杂功能的 watchOS 应用程序。 WatchKit Extension 中的 Assets.xcassets 文件包含一个 Complication 文件夹,其中每个
我无法在 WatchOS 3 中更新/刷新 Apple Watch Complication。我在我的 ComplicationController.swift 文件中使用了以下代码。 func ge
我的 WatchKit 扩展中有我需要的所有数据(从 iOS 应用程序传递)。 我使用 WatchKit InterfaceController 中的数据填充了一个表格,效果很好。 我正在尝试找出最佳
这个问题在这里已经有了答案: Convert Mat to Array/Vector in OpenCV (10 个答案) 关闭 4 年前。 我必须处理一个 .PNG 文件。该处理将 std::ve
我是一名优秀的程序员,十分优秀!