Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WatchKit data not displaying

I'm passing data from iOS to WatchKit. I can't get the data to show that was received on the WatchKit side somehow though.

This works fine: iOS TableViewController

func getCloudKit() {
    ///...
    let publicData = container.publicCloudDatabase
    publicData.performQuery(query, inZoneWithID: nil) { results, error in
        if error == nil { // There is no error
            for play in results! {
                let newPlay = Play()
                    newPlay.tColor = play["TColor"] as! String

                do {
                    try WatchSessionManager.sharedManager.updateApplicationContext(["color" : newPlay.tColor])
                    NSLog("NewPColor: %@", newPlay.tColor)
                } catch {
                    print(error)
                }
                self.objects.append(newPlay)
            }
        } else {
            print(error)
        }
    }
}

This isn't calling any of the NSLogs or showing any of the data: WatchKit InterfaceController

import WatchConnectivity


class InterfaceController: WKInterfaceController, WCSessionDelegate {

    @IBOutlet var colorLabel: WKInterfaceLabel!

    private let session: WCSession? = WCSession.isSupported() ? WCSession.defaultSession() : nil

    private func configureWCSession() {
        session?.delegate = self;
        session?.activateSession()
    }

    override init() {
        super.init()
        configureWCSession()
    }

    override func awakeWithContext(context: AnyObject?) {
        super.awakeWithContext(context)
    }

    func session(session: WCSession, didReceiveApplicationContext applicationContext: [String : AnyObject]) {
        let colorWatch = applicationContext["color"] as? String
        NSLog("Check if anything here: %@", colorWatch!)

                dispatch_async(dispatch_get_main_queue()) {
                    if let colorWatch = colorWatch {
                        self.colorLabel.setText("From iPhone: \(colorWatch)")
                        NSLog("Heres all the strings %@", colorWatch)
                    } else {
                        NSLog("Nothing")
                    }
                }
    }


}

Any ideas? Thanks!

like image 944
SRMR Avatar asked Oct 31 '22 18:10

SRMR


1 Answers

Try checking if session is nil with something like (my swift foo is weak):

  private func configureWCSession() {
    print("session: \(session?))
    session?.delegate = self;
    session?.activateSession()
}
like image 59
ccjensen Avatar answered Nov 15 '22 05:11

ccjensen