【发布时间】:2015-09-26 23:03:01
【问题描述】:
我无法呼叫didReceiveApplicationContext。有什么想法吗?
InterfaceController:
import WatchKit
import Foundation
import WatchConnectivity
class InterfaceController: WKInterfaceController, WCSessionDelegate {
@IBOutlet var colorLabel: WKInterfaceLabel!
private let session: WCSession? = WCSession.isSupported() ? WCSession.defaultSession() : nil
override init() {
super.init()
session?.delegate = self
session?.activateSession()
}
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
}
func session(session: WCSession, didReceiveApplicationContext applicationContext: [String : AnyObject]){
let colors : String = applicationContext["color"] as! String
colorLabel.setText(colors)
NSLog("session did receive application context")
}
}
我一直在关注本教程:http://www.kristinathai.com/watchos-2-how-to-communicate-between-devices-using-watch-connectivity/
没有NSLog 或colorLabel 的设置发生。不知道我错过了什么。谢谢!
【问题讨论】:
-
您可以发布发送方的代码吗?发送端是否有任何错误返回?
-
发送方没有返回错误。如果您让我知道您需要它,我仍然可以发布代码,但是发送方都很好。如果是这样,请告诉我。谢谢!
标签: swift watchkit xcode7 watchos-2