Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Jared Gross
2,686 PointsimagePicker freezing upon image upload
I have an imagePicker that takes pictures and uploads them to Parse. Only problem is whenever I upload an image, the image is frozen in the view. The app, however, is not frozen because I have an overlay view with a UILabel as a timer and the timer still counts down. I've tried many different placement combinations of dismissing and presenting the viewControllers/imagePicker as well as not calling either but haven't been successful yet. any help is greatly appreciated, thanks!
// uploads the files/data to Parse
- (void)uploadMessage {
NSData *fileData;
NSString *fileName;
NSString *fileType;
if (self.image != nil) {
UIImage *newImage = [self resizeImage:self.image toWidth:320.0f andHeight:480.0f];
fileData = UIImagePNGRepresentation(newImage);
fileName = @"image.png";
fileType = @"image";
}
else {
fileData = [NSData dataWithContentsOfFile:self.videoFilePath];
fileName = @"video.mov";
fileType = @"video";
}
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 file again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
else {
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
PFObject *image = [PFObject objectWithClassName:@"Images"];
[image setObject:file forKey:@"file"];
[image setObject:fileType forKey:@"fileType"];
[image setObject:self.recipients forKey:@"recipientIds"];
[image setObject:[[PFUser currentUser] objectId] forKey:@"senderId"];
[image setObject:[[PFUser currentUser] username] forKey:@"senderName"];
[image saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"An error occurred!"
message:@"Please try sending your file again."
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
else {
NSLog(@"everything was successfull");
[self reset];
}
}];
}
}];
}
// resets the current data
- (void)reset {
self.image = nil;
self.videoFilePath = nil;
NSLog(@"Reset was succes!");
}
1 Answer
Amit Bijlani
Treehouse Guest TeacherThe only potential problem I can see is that you have nested saveInBackgroundWithBlock. Instead, you might want to have server side code where you send the file and it creates the necessary relationships on the server. See: https://parse.com/docs/cloud_code_guide