ios - 在一个 PFFile 中获取两个数据

标签 ios objective-c parse-platform pffile

我想在一个 PFFile 中保存 2 个数据:一个图像和一个数据声音。 这对于图像 (fileData) 来说是正确的,但我想在 Parse.com 中为数据声音 (fileData2) 添加一列。我怎样才能做到这一点?我不能这样做:“PFFile *file = [PFFile fileWithName:fileName data:fileData,fileData2];”

这是我的代码:

- (void)uploadMessage {
    NSData *fileData;
    NSData *fileData2;
    NSString *fileName;
    NSString *fileType;

    if (self.image != nil) {
        [SVProgressHUD showWithStatus:@"Sending..." maskType:SVProgressHUDMaskTypeClear];
        UIImage *newImage = [self resizeImage:self.image toWidth:320.0f andHeight:480.0f];
        fileData = UIImagePNGRepresentation(newImage);
        fileData2 = self.datasound;
        fileName = @"image.png";
        fileType = @"image";
    }

    PFFile *file = [PFFile fileWithName:fileName data:fileData];
    [file saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (error) {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"An error occurred!"
                                                                message:@"Please try sending your message again."
                                                               delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [SVProgressHUD dismiss];
            [alertView show];
        }
        else {
            PFObject *message = [PFObject objectWithClassName:@"Messages"];
            [message setObject:file forKey:@"file"];
            [message setObject:fileType forKey:@"fileType"];
            [message setObject:self.recipients forKey:@"recipientIds"];
            [message setObject:[[PFUser currentUser] objectId] forKey:@"senderId"];
            [message setObject:[[PFUser currentUser] valueForKey:@"name"] forKey:@"senderName"];
            [message saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
                if (error) {
                    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"An error occurred!"
                                                                        message:@"Please try sending your message again."
                                                                       delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                    [SVProgressHUD dismiss];
                    [alertView show];
                }
                else {
                    // Everything was successful!
                    [self reset];
                    [SVProgressHUD dismiss];
                }
            }];
        }
    }];
}

最佳答案

您无法(轻松)将两个文件放入一个 PFFFile 中。 PFFFile 旨在代表一个文件。

创建 PFFile 的两个实例,一个用于图像,一个用于声音文件。

PFFile *imageFile = [PFFile fileWithName:imageFileName data:imageFileData];
PFFile *soundFile = [PFFile fileWithName:soundFileName data:soundFileData];

将 PFFile 的这些实例设置为相应的解析列。例如:

[message setObject:imageFile forKey:@"imageFile"];
[message setObject:soundFile forKey:@"soundFile];

关于ios - 在一个 PFFile 中获取两个数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25876185/

相关文章:

objective-c - 制作离屏可拖动 View (如 iOS 5 通知中心)

android - 解析 API 本地数据存储 - pinInBackground()

ios - 从 Apple Health Kit 获取每日步数的最佳方法

objective-c - 带有嵌套页面的 UITabbarcontroller - 无法让选项卡栏控件显示根目录

iphone - 打字时如何将文本字段格式设置为十进制?

ios - NSURLConnection 取消回调

parse-platform - 限制用户更新某些字段但允许后端编辑它们

ios - 不同格式的 NSJSONSerialization 数据

ios - 标准 UIBarButtonItem 溢出菜单图标

ios - TabviewController如何显示未读消息(如角标(Badge))?