How to start watchApp from iPhone

我的梦境 提交于 2019-12-11 16:14:37

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!