gpt4 book ai didi

ios - WatchKit 数据不显示

转载 作者:搜寻专家 更新时间:2023-10-31 08:05:04 25 4
gpt4 key购买 nike

我正在将数据从 iOS 传递到 WatchKit。 但我无法获得显示在 WatchKit 端收到的数据

这很好用: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)
}
}
}

这不是调用任何 NSLog 或显示任何数据: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")
}
}
}


}

有什么想法吗?谢谢!

最佳答案

尝试检查 session 是否为零(我的 swift foo 很弱):

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

关于ios - WatchKit 数据不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32801818/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com