Watchkit and WCSession

Nicola

In my little experience I noticed that creating two or more Interface Controller (IC) for a WatchKit app, the AppleWatch start to load the next interface before the user swipe to it. This could be useful for system performances, but then there is something confusing me. For what I have understood each IC should have its own WCSession to communicate with the paired iPhone, but I'm starting thinking this is not true because debugging I saw that if for example the first IC use sendMessage to send a request, the answer is received by the didReceiveMessage of the second IC not the first IC. I didn't tried it yet, but maybe I should create the WCSession only in the first IC, and also if I am on another IC the app fire it in the didReceiveMessage of the first. If this is right, how can I do something in the second IC when a message arrives? In WatchKit I don't think I can use Observers. Can someone clarify me this, please?

Doing some more search over internet I've found this: http://www.sneakycrab.com/blog/2015/5/26/wkinterfacecontroller-lifecycle-in-watchos-101 This is the confirmation about the preload of IC, that still the same also in WatchOS 2.

Nicola

Using global public variables now I'm able to have the correct session fired.

----- myVariables.swift -----
public var showPage1: Bool = false

----- myMainIC.swift -----
override func willActivate() {
    super.willActivate()
    showPage1 = false
}

----- mySecondIC.swift -----
var session: WCSession?
override func WillActivate() {
    super.willActivate()
    // this way I can manage the pre-load
    if (showPage1 == false) {
        showPage1 = true
        return
    }
    // now I can create the session
    if WCSession.isSupported() {
        session = WCSession.defaultSession()
        session.delegate = self
        session.activateSession()
    }
}

Because of system pre-load explained in the above article, I should "teach" the mySecondIC to not create the session the first time the page is activate cause is invisible.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

WCSession in iOS App using WatchKit 2 Stops App Building

From Dev

WCSession and Today Widget

From Dev

Close/Deactivate WCSession

From Dev

WCSession File Transfer Issue

From Dev

WCSession only working once

From Dev

WCSession only working once

From Dev

watchOS WCSession 'paired' and 'watchAppAvailable' are unavailable

From Dev

When to call activateSession() on WCSession object

From Dev

WCSession transferUserInfo only works in Foreground

From Dev

SPErrorGizmoInstallNeverFinishedErrorMessage in Watchkit

From Dev

WatchKit Upload

From Dev

IBInspectable & watchkit

From Dev

WatchKit and Geolocation

From Dev

WCSession.sendMessage works 50/50

From Dev

Using WCSession with more than one ViewController

From Dev

WCSession didReceive file not movable "No such file or directory"

From Dev

watchOS, WCSession activationDidCompleteWith "activated", yet is not reachable

From Dev

WatchOS2 WCSession How many delegates can the WCSession have in WatchKitExtension?

From Dev

WatchKit: Speech to text conversion in WatchKit Apps

From Dev

Social Framework for WatchKit

From Dev

WatchKit SMS with preset body

From Dev

Is there an equivalent class to UIView in WatchKit?

From Dev

Populating TableView in WatchKit Error

From Dev

WatchKit and MagicalRecord - is that possible?

From Dev

WatchKit and UIAlertView / UIAlertController popup

From Dev

Submit WatchKit Provisioning Error

From Dev

Scroll to top of WKInterfaceTable in WatchKit?

From Dev

Is there an ActivityIndicator in WatchKit for Apple Watch?

From Dev

Parse Query in WatchKit