带解析的用户照片(个人资料图片)问题

时间:2013-12-30 23:35:56

标签: ios image photo parse-platform

我的用户照片(个人资料照片)存在一些问题。每次单个用户更新其个人资料图片时,它还会使用相同的图像更新其余用户。如何更改它以使其无处不变?我正在使用parse.com

我使用以下代码。

上传照片:

- (void)uploadProfilePhoto {
NSData *imageData;
NSString *imageName;
NSString *imageType;

//Shrink it
//Upload profile photo

(self.image != nil); {
    UIImage *resizeImage = [self resizeImage:self.image toWidth:320.0f andHeight:320.0f];
    imageData = UIImagePNGRepresentation(resizeImage);
    imageName = @"profileimage.png";
    imageType = @"image";
}

PFFile *image = [PFFile fileWithName:imageName data:imageData];
[image saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    if (error) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Something went wrong!" message:@"Please try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
    }
    else {
        PFObject *UserPhotos = [PFObject objectWithClassName:@"UserPhoto"];
        [UserPhotos setObject:image forKey:@"image"];
        [UserPhotos setObject:imageType forKey:@"imageType"];
        [UserPhotos setObject:[PFUser currentUser] forKey:@"user"];
        [UserPhotos setObject:[[PFUser currentUser] objectId] forKey:@"uploaderId"];
        [UserPhotos setObject:[[PFUser currentUser] username] forKey:@"uploaderUsername"];
        [UserPhotos saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
            if (error) {
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Something went wrong!" message:@"Please try uploading your photo again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alertView show];
            }
            else {
                //Everything was successfull!

            }
        }];
    }
}];

}

当我检索照片时:

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

PFQuery *query = [PFQuery queryWithClassName:@"UserPhoto"];
[query includeKey:@"user"];
[query orderByDescending:@"createdAt"];
[query getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) {
    if (!object) {
        return NSLog(@"%@", error);
    }

    PFFile *imageFile = object[@"image"];

    [imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
        if (!data) {
            return NSLog(@"%@", error);
        }

        // Do something with the image
        self.profileImage.image = [UIImage imageWithData:data];
    }];
}];

[self.navigationController.navigationBar setHidden:YES];

}

谢谢!

0 个答案:

没有答案