本文介绍了如何从 iPhone 启动 watchApp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发手表应用程序,我希望在 iPhone 上启动该应用程序时激活手表应用程序,但我不知道如何操作.

I am developing a watch app and I want the watch app to activate when I start the app on the iPhone, but I can't find out how to do that.

该问题已在多个论坛中提出,答案始终是不可能",但必须有另一个答案,因为有很多应用程序会自动打开手表应用程序:地图、播客等等二.那么秘诀是什么?

The question has been asked in a number of forums and the answer has always been "Not possible", but there must be another answer as there are plenty of apps that do open the watch app automatically: Maps, Podcasts to name but two.So what's the secret?

推荐答案

这是代码片段.您应该只将它用于锻炼应用程序,但在手表方面,您实际上不必启动 HKWorkoutSession.

Here is the code snippet. You are supposed to only use it for a workout app but on the watch side you don't really have to start HKWorkoutSession.

    let workoutConfiguration = HKWorkoutConfiguration()
    workoutConfiguration.activityType = .traditionalStrengthTraining
    workoutConfiguration.locationType = .indoor
    if WCSession.isSupported(), WCSession.default().activationState == .activated , WCSession.default().isWatchAppInstalled{
        healthStore.startWatchApp(with: workoutConfiguration, completion: { (success, error) in
            print(error.debugDescription)
        })
    }

这篇关于如何从 iPhone 启动 watchApp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 18:21