Parse platform saveInBackgroundWithBlock完成工作时不调用块

Parse platform saveInBackgroundWithBlock完成工作时不调用块,parse-platform,Parse Platform,我试图用Obj-C在iOS中进行简单的聊天,当我按下“发送”按钮时,我将对象保存到Parse中,并检索所有消息 当它成功时,我检索所有消息,所以最后一条(我的)也应该被检索,但最后一条永远不会被调用。我该怎么办 这是我的代码: NSMutableArray *messagesArray; - (IBAction)sendButtonTapped:(id)sender { self.sendButton.enabled = false; self.textField.enabl

我试图用Obj-C在iOS中进行简单的聊天,当我按下“发送”按钮时,我将对象保存到Parse中,并检索所有消息

当它成功时,我检索所有消息,所以最后一条(我的)也应该被检索,但最后一条永远不会被调用。我该怎么办

这是我的代码:

NSMutableArray *messagesArray;

- (IBAction)sendButtonTapped:(id)sender {

    self.sendButton.enabled = false;
    self.textField.enabled = false;
    PFObject *objectChat = [PFObject objectWithClassName: @"ChatClass"];

    objectChat[@"text"] = self.textField.text;

    [objectChat saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {


        self.sendButton.enabled = true;
        self.textField.enabled = true;

        if (succeeded) {
            self.textField.text = @"";

            [self retrieveMessages];

            NSLog(@"success!");
        } else {
            NSLog(error.description);
        }

    }];


}

-(void) retrieveMessages {
    NSDate *now = [NSDate date];

    PFQuery *query = [PFQuery queryWithClassName:@"ChatClass"];
    [query whereKey:@"createdAt" lessThanOrEqualTo:now];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {


        if (error == nil) {

            messagesArray = [[NSMutableArray alloc] init];

            for (int i = 0; i < [objects count]; i++) {

                [messagesArray addObject:[[objects objectAtIndex:i] objectForKey:@"text"]];
            }

            runOnMainQueueWithoutDeadlocking(^{

                [self.messageTableView reloadData];

            });

        }

    }];
}

void runOnMainQueueWithoutDeadlocking(void (^block)(void))
{
    if ([NSThread isMainThread])
    {
        block();
    }
    else
    {
        dispatch_async(dispatch_get_main_queue(), block);
    }
}
NSMutableArray*messagesArray;
-(iAction)sendButtonTapped:(id)发件人{
self.sendButton.enabled=false;
self.textField.enabled=false;
PFObject*objectChat=[pfobjectobjectwithclassname:@“ChatClass”];
objectChat[@“text”]=self.textField.text;
[objectChat SaveInBackgroundithBlock:^(布尔成功,N错误*错误){
self.sendButton.enabled=true;
self.textField.enabled=true;
如果(成功){
self.textField.text=@”;
[自我检索信息];
NSLog(@“成功!”);
}否则{
NSLog(错误描述);
}
}];
}
-(无效)检索邮件{
NSDate*现在=[NSDate日期];
PFQuery*query=[pfqueryquerywithclassname:@“ChatClass”];
[查询whereKey:@“createdAt”lessThanOrEqualTo:now];
[查询findObjectsInBackgroundWithBlock:^(NSArray*对象,NSError*错误){
如果(错误==nil){
messagesArray=[[NSMutableArray alloc]init];
对于(int i=0;i<[对象计数];i++){
[messagesArray addObject:[[objects objectAtIndex:i]objectForKey:@“text”];
}
在没有死锁的情况下运行MainQueue(^{
[self.messageTableView-reloadData];
});
}
}];
}
void runnonmainqueuewithout死锁(void(^block)(void))
{
如果([NSThread isMainThread])
{
block();
}
其他的
{
dispatch_async(dispatch_get_main_queue(),block);
}
}
事先非常感谢。
关于。

也许解析服务器的时钟差异足够大,以至于时间限定忽略了刚刚创建的对象。去掉那条线就行了

为什么还要将查询限定为,不需要在没有死锁的情况下运行nmainqueuewithoutdeadlocking()。parse.com完成块在main.Hi@danh上运行。“runOnMainQueueWithouthDeadlocking()是因为我不确定它是否在主线程上执行,只是为了防止出错。最初的错误是我的计算机和服务器之间的时钟差。请将此评论更新为响应?非常感谢!!!完成。很高兴它有帮助。