check apple watch is connected

53 views Asked by At

I want to check whether Apple Watch is connected to the iPhone and then check whether the remotePaymentPass is available or not for Apple Pay. However, it was no luck. It said wcsessiondelegate not found. Anyone can help?

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) {
    }
}
0

There are 0 answers