HKWorkoutSession并未将应用程序放在Apple Watch的前面 [英] HKWorkoutSession isn't keeping app at front of Apple Watch

查看:245
本文介绍了HKWorkoutSession并未将应用程序放在Apple Watch的前面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已经说过,运行HKWorkoutSession的应用程序将具有其他watchOS 2应用程序的特殊特权,因此,当用户查看其Apple Watch时,它将转到显示正在运行锻炼而不是表盘的视图.

It has been stated that an app running a HKWorkoutSession will have special privileges over other watchOS 2 apps, so when a user looks at their Apple Watch, it will go to the view showing running a workout rather than the watch face.

当前,在我的设备和模拟器上均不是这种情况.如果我启动HKWorkoutSession然后离开5分钟,然后与Apple Watch或Watch Simulator交互,它将显示表盘.

Currently, on both my device and simulator, this is not the case. If I start a HKWorkoutSession and then leave for 5 minutes and then interact with either the Apple Watch, or the Watch Simulator, it presents the watch face.

如果我随后打开我的应用程序,则它似乎已冻结,而不是终止(这是我想象的其他应用程序发生的情况).因为UI将在我需要在query.updateHandler中接收响应时更新.另外,如果我将其设置为每次query.updateHandler接收到新的HKQuantitySample时都会提供触觉反馈,则它将这样做,因此该应用程序必须以某种形式在后台运行.

If I then open my app, it appears to have been frozen, rather than terminated (which is what I imagine happens to other apps). As the UI will update when I need receive a response in my query.updateHandler. Also if I set it to provide haptic feedback every time my query.updateHandler receives a new HKQuantitySample it will do so, so the app must be running in the background in some form.

还有其他人注意到这种行为吗?我做错了什么吗?还是期待某些我不应该做的事情?

Has anyone else noticed this behaviour, and am I doing anything wrong, or expecting something I shouldn't?

这是我开始HKWorkoutSession的方式:

Here is how I start my HKWorkoutSession:

    self.workoutSession = HKWorkoutSession(activityType: HKWorkoutActivityType.Other, locationType: HKWorkoutSessionLocationType.Indoor)

        self.healthStore.startWorkoutSession(self.workoutSession) {
            success, error in

            if error != nil {
                print("startWorkoutSession \(error)\n")
                self.printLabel.setText("startWorkoutSession \(error)")
                self.printLabel.setTextColor(UIColor.redColor())
            }

推荐答案

我们也看到了这一点,目前,我们已经确保已配置打开上一个活动".

We're seeing that too, for the moment we've made sure 'opens last activity' is configured.

当用户界面处于活动状态时,我们启动dispatch_timer,以每隔1秒的间隔请求和处理数据.

When the UI is active we start a dispatch_timer to request and process data in 1 second intervals.

但是请确保使用NSUserProcessInfo方法进行任何重要的处理,并在不再活动时暂停一下dispatch_timers.否则,您将崩溃.

Make sure you do any significant processing using the NSUserProcessInfo method though and pause the dispatch_timers whenever you are no longer active. You'll get crashes otherwise.

这篇关于HKWorkoutSession并未将应用程序放在Apple Watch的前面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆