【问题标题】:How to get pffile from pfobject using Parse如何使用 Parse 从 pfobject 获取 pffile
【发布时间】:2014-12-04 18:46:08
【问题描述】:

我正在尝试通过以下方式从我的 PFUser 对象中获取文件:

PFFile *userImageFile = gaUser[@"@userImage"];

这将返回 nil。

这就是我的方法中的样子:

- (void)getRemoteImageAndSaveLocalWithObjectId:(NSString *)objectId andType:(NSString *)type{
    if ([type isEqualToString:@"user"]) {
        PFQuery *query = [GAUser query];
        // I tried the include key but I get an error.
        //[query includeKey:@"userImage"];
        [query getObjectInBackgroundWithId:objectId block:^(PFObject *object, NSError *error) {
            GAUser *gaUser = (GAUser *)object;
            // this is nil
            PFFile *userImageFile = gaUser[@"userImage"];

            if (userImageFile){
            [userImageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
                NSLog(@"in get data");
                if (!error) {

                    NSLog(@"remote image name: %@",data.debugDescription);

                    UIImage *image = [UIImage imageWithData:data];


                }else{

                    NSLog(@"there was an error");
                }
            }];
            }else{
                NSLog(@"user image file is nil");
            }

        }];
    }

打印:user image file is nil

我的解析控制台如下所示:

我做错了什么?

【问题讨论】:

  • 为什么你用@userImage而不是userImage来索引字符串?

标签: ios objective-c parse-platform


【解决方案1】:

由于在 Parse 中您的列被命名为 userImage,您应该通过以下方式访问它:

PFFile *userImageFile = gaUser[@"userImage"];

而不是

PFFile *userImageFile = gaUser[@"@userImage"];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-20
    • 1970-01-01
    • 2014-12-21
    • 1970-01-01
    • 2014-08-07
    • 1970-01-01
    • 2015-03-26
    相关资源
    最近更新 更多