如何从 parent iOS 应用程序打开手表应用程序?
How to open a watch app from parent iOS app?
我需要从我的 parent iOS 应用打开我的手表扩展程序。
我在 Nike+ 运行 Club 应用程序中看到了类似的功能。即,当用户点击 Parent 应用程序中的“开始”按钮时,将立即打开手表套件扩展程序。
正如@abjurato 所说,您只能在 "workout mode"
中启动它
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
}
}
我需要从我的 parent iOS 应用打开我的手表扩展程序。 我在 Nike+ 运行 Club 应用程序中看到了类似的功能。即,当用户点击 Parent 应用程序中的“开始”按钮时,将立即打开手表套件扩展程序。
正如@abjurato 所说,您只能在 "workout mode"
中启动它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
}
}