问题
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?
回答1:
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)
})
}
来源:https://stackoverflow.com/questions/50033295/how-to-start-watchapp-from-iphone