Parse.com的奇怪问题,其中不包含密钥 [英] Strange issue with Parse.com with key not being included

查看:80
本文介绍了Parse.com的奇怪问题,其中不包含密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题与此基本上,我正在使用Parse.com加载一些具有PFUser指针的对象,然后还使用includeKey来包含那些PFUser,这是代码...

Basically I'm using Parse.com to load some objects, which have PFUser pointers, and then I'm also using includeKey to include those PFUsers, here's the code...

PFQuery *query = [PFQuery queryWithClassName:@"GameVillageObject"];

    [query whereKey:@"region" equalTo:[NSNumber numberWithInt:region]];
    [query includeKey:@"pfUser"];
    query.limit = 100;

    [sharedInstance requestSentWithDesc:@"Get all village objects in region"];

    [query findObjectsInBackgroundWithBlock:^(NSArray *PUObjects, NSError *error) {
        if (!error) {
            // The find succeeded.
            NSLog(@"Successfully retrieved %d village objects from server.", PUObjects.count);

            if(PUObjects.count > 0)
            {
                villageObjects = PUObjects;

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

                    PFObject *villageItem = [villageObjects objectAtIndex:i];

                    PFUser *user = [villageItem objectForKey:@"pfUser"];

                    NSString *userName = [NSString stringWithFormat:@"%@",[user objectForKey:@"username"]];

                    NSLog(@"User name is: %@.", userName);


                }


                [self setupVillageList];

                [sharedInstance centerImage:marketItemsContainer xChoice:YES yChoice:NO];

            }

        } else {
            // Log details of the failure
            NSLog(@"Getting village objects Error: %@ %@", error, [error userInfo]);

        }
    }];

现在由于某种原因,一次又一次,也许十分之一,游戏崩溃了,并出现了这个错误

Now for some reason, everynow and again, maybe 1 time out of 10, the game is crashing, with this error

键用户名"没有数据.调用fetchIfNeeded,然后再获取它 值.

Key "username" has no data. Call fetchIfNeeded before getting its value.

虽然当我尝试使用上面的用户名"时,或者当我尝试使用用户名"时,我无法分辨它是否崩溃了,但是无论哪种方式,我都无法理解为什么大多数情况下它都崩溃了没问题,包括那些多余的对象,然后几次没有.有什么想法吗?

Although I can't tell if it's crashing when I try to use "username" above, or a little later when I try to use "username" but either way, I don't get why most of the time it has no problem including those extra objects and then a few times it doesn't. Any ideas?

推荐答案

听起来好像未加载关联的user,但是在大多数情况下都可以缓存(因此可用).我可以想到两种解决方法.

It sounds as though the associated user is not being loaded, but may be cached in most instances (and thus available). I can think of two ways to resolve this.

1)按照错误消息的建议调用fetchIfNeeded:

1) Call fetchIfNeeded as suggested by the error message:

PFQuery *query = [PFQuery queryWithClassName:@"GameVillageObject"];

[query whereKey:@"region" equalTo:[NSNumber numberWithInt:region]];
[query includeKey:@"pfUser"];
...
  PFObject *villageItem = [villageObjects objectAtIndex:i];

  PFUser *user = [villageItem objectForKey:@"pfUser"];
  [user fetchIfNeeded];
  NSString *userName = [NSString stringWithFormat:@"%@",[user objectForKey:@"username"]];

  NSLog(@"User name is: %@.", userName);

2)在includeKey:调用中指定pfUser.username

[query whereKey:@"region" equalTo:[NSNumber numberWithInt:region]];
[query includeKey:@"pfUser.username"];
query.limit = 100;
...

这应该告诉Parse在执行查询时加载username.

This should tell Parse to load username when the query is executed.

这篇关于Parse.com的奇怪问题,其中不包含密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆