gpt4 book ai didi

swift - 如何从父 iOS 应用程序打开 watch 应用程序?

转载 作者:搜寻专家 更新时间:2023-10-31 08:17:41 24 4
gpt4 key购买 nike

我需要从我的父级 iOS 应用打开我的 watch 扩展程序。我在 Nike+ Run Club 应用程序中看到了类似的功能。即,当用户点击父应用程序中的开始按钮时,将立即打开 watch 套件扩展。

最佳答案

正如@abjurato 所说,您只能在“锻炼模式”下启动它

import HealthKit
import WatchConnectivity
let healthStore = HKHealthStore()

func startWatchApp() {
print("method called to open app ")

getActiveWCSession { (wcSession) in
print(wcSession.isComplicationEnabled, wcSession.isPaired)
if wcSession.activationState == .activated && wcSession.isWatchAppInstalled {
print("starting watch app")

self.healthStore.startWatchApp(with: self.configuration, completion: { (success, error) in
// Handle errors
})
}

else{
print("watch not active or not installed")
}
}

}

func getActiveWCSession(completion: @escaping (WCSession)->Void) {
guard WCSession.isSupported() else { return }

let wcSession = WCSession.default()
wcSession.delegate = self

if wcSession.activationState == .activated {
completion(wcSession)
} else {
wcSession.activate()
wcSessionActivationCompletion = completion
}
}

关于swift - 如何从父 iOS 应用程序打开 watch 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43042236/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com