如何从iPhone启动watchApp [英] How to start watchApp from iPhone
问题描述
我正在开发一个手表应用程序,我希望在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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!