Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios WatchKit数据未显示_Ios_Swift_Watchkit_Watchos 2 - Fatal编程技术网

Ios WatchKit数据未显示

Ios WatchKit数据未显示,ios,swift,watchkit,watchos-2,Ios,Swift,Watchkit,Watchos 2,我正在将数据从iOS传递到WatchKit我无法获得数据来显示在WatchKit端接收到的数据 这工作正常:iOSTableViewController func getCloudKit() { ///... let publicData = container.publicCloudDatabase publicData.performQuery(query, inZoneWithID: nil) { results, error in if error

我正在将数据从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)
        }
    }
}
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")
                    }
                }
    }


}
这不会调用任何
NSLog
s或显示任何数据:WatchKit
InterfaceController

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)
        }
    }
}
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")
                    }
                }
    }


}

有什么想法吗?谢谢

尝试使用以下内容检查会话是否为零(我的swift foo很弱):


什么是WatchSessionManager,它是否确保设置并激活WCSession?
WatchSessionManager
是一个设置并激活WCSession的单例类。这是在iOS端,所以当我记录所有内容时,这一部分工作得非常完美。手表套件的一面不太好用。有什么想法吗?会话在configureWCSession()中可能为零吗?嗯,可能吧,你如何再检查一下?我做了
打印(“会话:\(会话)”)
并且它给了我`session:Optional()`所以我想你是对的?嗯。。。尝试在调用activateSession之后添加打印(“会话…”。然后打印什么?是的,它在
activateSession()
之后工作::“session:Optional()”在手表端是session.reachable true?applicationContext不需要它,但可能会提供一个类似于true的ClueLook。如果(session?.reachable!=nil),我这样做了
if(session?.reachable!=nil){NSLog(“Yes”)}
NSLog
ged“Yes”。