提问人:invu 提问时间:10/31/2023 更新时间:10/31/2023 访问量:23
检查 Apple Watch 是否已连接
check apple watch is connected
问:
我想检查Apple Watch是否连接到iPhone,然后检查remotePaymentPass是否可用于Apple Pay。然而,这不是运气。它说找不到 wcsessiondelegate。有人可以帮忙吗?
import WatchConnectivity
protocol PairedDeviceRepository {
func hasPairedWatchDevices() -> Bool
}
class PairedDeviceRepositoryImpl: NSObject, PairedDeviceRepository {
func hasPairedWatchDevices() -> Bool {
guard WCSession.isSupported() else { return false }
let session = WCSession.default
session.delegate = self
session.activate()
print("Watch isPaired: \(session.isPaired) ")
return session.isPaired
}
}
extension PairedDeviceRepositoryImpl: WCSessionDelegate {
// WCSessionDelegate methods
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
if session.isPaired {
print("Watch is paired")
} else {
print("Watch is not paired")
}
}
func sessionDidDeactivate(_ session: WCSession) {
}
func sessionDidBecomeInactive(_ session: WCSession) {
}
}
答: 暂无答案
评论