2

I'm implementing the new WCSessionDelegate methods to support multiple device pairing.

- (void)session:(WCSession *)session activationDidCompleteWithState:(WCSessionActivationState)activationState error:(nullable NSError *)error;
- (void)sessionDidBecomeInactive:(WCSession *)session;
- (void)sessionDidDeactivate:(WCSession *)session;

I'm a bit unsure about how these methods will work with older versions of iOS and watchOS (the Simulator is proving very unhelpful).

My assumption is that these methods will replace the behaviour controlled through the method below, and I can exclude it?

- (void)sessionWatchStateDidChange:(WCSession *)session;

Has anyone had experience with supporting combinations of older iOS and watchOS devices with these new methods?

Ricky
  • 3,101
  • 1
  • 25
  • 33

1 Answers1

0

The new session activation methods don't replace the state change method. You will continue to receive state change notifications for the active watch since some property changes may not be related to the watch being switched.

For example, the user may install or delete the companion watch app, or enable or disable the complication on the currently active watch.

Supporting older versions of iOS:

The delegate methods themselves won't get called on older versions of the OS. You merely need to ensure you don't access any properties or call any methods which would only be available on newer versions of the OS.

You should use #if available to dynamically check the OS version that your app is running on (since activationState is only available since 9.3).

Here's an example demonstrating how you could support multiple versions of iOS:

private func isValidSession() -> Bool {
    if #available(iOS 9.3, *) {
        guard let session = session where session.activationState == .Activated && session.paired && session.watchAppInstalled else {
            return false
        }
    } else {
        // Fallback on earlier versions
        guard let session = session where session.paired && session.watchAppInstalled else {
            return false
        }
    }
    return true
}

Sample code:

Apple has also provided QuickSwitch sample code which you may find helpful in supporting or experimenting with watch switching.

Community
  • 1
  • 1