ios - 如何使用 Parse 从 pfobject 获取 pffile

标签 ios objective-c parse-platform

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

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

这将返回零。

这是我的方法中的样子:

- (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

我的解析控制台看起来像:

enter image description here

我做错了什么?

最佳答案

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

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

代替

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

关于ios - 如何使用 Parse 从 pfobject 获取 pffile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27301624/

相关文章:

ios - becomeFirstResponder 非常慢

iphone - 如何在不显示 MFMailComposeViewController 的情况下从 iPhone 应用程序发送邮件?

iphone - Collection View 中的单元格不可见

objective-c - 应用程序崩溃并显示 "Unable to restore previously selected frame"消息

iphone - 获取文件名到 NSArray

ios - 解析单个字符串字段的查询,其中值与数组中提供的任何字符串匹配

java - Jar 未添加到类路径 - Android Studio

iphone - 应用程序像 iphone 4 一样在 iphone 5 上运行

ios - iOS 的 APNS 通知声音

javascript - 解析作业未按计划时间间隔运行