2015-09-26 23 views
5

Tôi đang chuyển dữ liệu từ iOS sang WatchKit. Tôi không thể nhận được dữ liệu để hiển thị rằng đã nhận được ở mặt bên WatchKit bằng cách nào đó.Dữ liệu WatchKit không hiển thị

này hoạt động tốt: 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) 
     } 
    } 
} 

này không gọi bất kỳ NSLog s hoặc hiển thị bất kỳ dữ liệu: 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") 
        } 
       } 
    } 


} 

Bất kỳ ý tưởng? Cảm ơn!

+0

WatchSessionManager là gì, và nó chắc chắn để thiết lập WCSession và kích hoạt nó? – ccjensen

+0

'WatchSessionManager' là một lớp đơn để thiết lập WCSession và kích hoạt nó. Đó là ở phía iOS, do đó, một phần hoạt động hoàn hảo khi tôi đăng nhập tất cả mọi thứ. Phía WatchKit là một bên không hoạt động tốt. Bất kỳ ý tưởng? – SRMR

+0

Có phiên trong configureWCSession() không? – ccjensen

Trả lời

2

Hãy thử kiểm tra nếu phiên là con số không với một cái gì đó tương tự (foo nhanh chóng của tôi là yếu):

private func configureWCSession() { 
    print("session: \(session?)) 
    session?.delegate = self; 
    session?.activateSession() 
} 
+0

Tôi đã làm 'in (' phiên: \ (phiên) ') 'và nó cho tôi' phiên: Tùy chọn () 'vì vậy tôi nghĩ rằng bạn đang ở một cái gì đó đúng ? – SRMR

+0

Hmmm ... Hãy thử thêm bản in ("phiên ... sau khi gọi để kích hoạt. Sau đó, nó sẽ in? – ccjensen

+1

Vâng nó hoạt động sau phiên' activateSession() ':": Tùy chọn () " – SRMR

Các vấn đề liên quan