WatchOS 2没有从iPhone AppDelegate

时间:2016-03-17 21:51:10

标签: swift ios9 appdelegate watch-os-2

我需要帮助或额外的眼睛来找出我的查询和方法没有将数据返回Apple Watch的原因。我试图用我的解析数据库中存储PFFiles的图像填充我的表。当我的消息需要返回String时,它们会通过,但不是在我请求NSData时。我已经学会了,因为Watch不符合解析协议,我不得不要求返回一个NSData文件。所以我试图在AppDelegate端转换它们,然后作为NSData传输。

这是我的AppDelegate:

let query = PFQuery(className: "dogInfo")
query.whereKey("userId", equalTo: (PFUser.currentUser()?.objectId)!)
query.orderByAscending("dogName")
query.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in

    if error == nil && objects!.count > 0 {

        var dataArray = [NSData]()

        for object in objects! {

            if let message = object["imageFile"] as? PFFile {

                message.getDataInBackgroundWithBlock({ (data, error) -> Void in

                    if error == nil {

                        dataArray.append(data!)
                    }
                })
            }
        }

        replyHandler(["images":dataArray])
    }
})

这就是我在Watch InterfaceController方面检索它的方式:

self.session.sendMessage(["content":"getImages"], replyHandler: { (result) -> Void in

    if let imagesRequest = result as? [String:[NSData]] {

        if let dogData = imagesRequest["images"] {

            self.imageFiles = dogData

            print("Imagefiles count:\(self.imageFiles.count)")                                              
            self.logInLabel.setHidden(true)
            self.loadTableData()
        }
    }

}, errorHandler: { (error) -> Void in
    print("got images error: \(error)")
})

1 个答案:

答案 0 :(得分:1)

您正在填充异步块(dataArray)内的message.getDataInBackgroundWithBlock,并在它有机会填充之前将其返回到该块之外。