【问题标题】:PFQuery not working correctlyPFQuery 无法正常工作
【发布时间】:2016-08-12 16:45:18
【问题描述】:

我有一些代码应该在我的 parse 后端搜索所有 MapPoints,检索与 id 匹配的 MapPoint,并将 MapPoint 的 title 值分配给一个字符串,所以我可以使用该字符串作为推送查询键的值。

NSLog(@"****staticobject****");
NSLog([[NSString alloc] initWithFormat: @"%@", staticObjectId]);

PFQuery *query = [PFQuery queryWithClassName:@"MapPoints"];
[query whereKey:@"marker_id" equalTo:[[NSNumber alloc] initWithInt:[staticObjectId intValue]]];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    NSLog(@"performed query");
    PFObject *object = [objects firstObject];
    newtitle = [[NSString alloc] initWithString:[object valueForKey:@"title"]];
    NSLog(@"***newtitle****");
    NSLog(newtitle);
}];

当我尝试使用 PFPush 时 - 我收到一条消息,指出 newtitle(null) - 这意味着永远不会输入上述查询。

[query whereKey:@"marker_id" equalTo:[[NSNumber alloc] ...]]]; 一定找不到任何东西。

这是第一个日志的控制台输出:

2016-08-12 12:34:41.355 sneek[1098:386496] ****staticobject**** 2016-08-12 12:34:41.356 sneek[1098:386496] 15768840

它应该在数据库中找到那个id,我已经验证它在那里。

【问题讨论】:

  • 为什么不记录错误信息?记录从 findObjectsInBackgroundWithBlock 返回的错误并发布您看到的内容
  • 没有错误 - 我有一个 if 块检查它,它永远不会进入查询。
  • 我明白了,然后取出这一行,看看 PFQuery 做了什么,你必须锁定它。去掉这一行,然后看查询是否运行: [query whereKey:@"marker_id" equalTo:[[NSNumber alloc] initWithInt:[staticObjectId intValue]]];
  • 好吧,现在就做一秒
  • 我收到Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: not found (404)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x15571e9f0> { URL: http://www.eamondev.com/sneekback/respond.php } { status code: 404, headers { Connection = "keep-alive"; "Content-Length" = 0; "Content-Type" = "application/json"; Date = "Fri, 12 Aug 2016 17:44:03 GMT"; Server = "nginx/1.10.1";

标签: ios objective-c google-maps parse-platform null


【解决方案1】:

我将查询移到更有意义的不同区域,我认为它不在AFNetworking 块中的事实可能是修复它的原因。

【讨论】:

    猜你喜欢
    • 2016-12-01
    • 1970-01-01
    • 2016-09-01
    • 2012-07-11
    • 2018-04-08
    • 2017-04-20
    • 2018-10-02
    • 2016-09-04
    • 2010-10-06
    相关资源
    最近更新 更多