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

General Discussion

Ribbit Application is Freezing upon sending a video!

Hi everyone -

So, I got all the way through creating the Ribbit app pretty seamlessly. Everything was working fine until... I tested sending videos on the app from my iPhone.

Yes, I'm compiling it for the correct iOS version (7.0).

I've tried commenting out 'unnecessary' sections to debug the problem, and I've found a common factor every time the (below) error comes up: --> the variable "videoFilePath".

(The error that pops up is "Thread 1:EXC_BAD_ACCESS (code=1, address=0x20)")

Here is what I need to do to make the error occur: Click on Camera>Record video>Checkmark some friends>Send. As soon as I click send, the error occurs.

Here's my code for reference (in InboxViewController):

#import "InboxViewController.h"



@interface InboxViewController ()

@end

@implementation InboxViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.tableView reloadData];
    self.moviePlayer = [[MPMoviePlayerController alloc] init];
    PFUser *currentUser = [PFUser currentUser];
    if (currentUser) {
        NSLog(@"Current user: %@", currentUser.username);
    } else {

        [self performSegueWithIdentifier:@"showLogin" sender:self];
    }



}

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

    PFQuery *query = [PFQuery queryWithClassName:@"Messages"];
    [query whereKey:@"recipientIds" equalTo:[[PFUser currentUser] objectId]];
    [query orderByDescending:@"createdAt"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (error) {
            NSLog(@"Error: %@ %@", error, [error userInfo]);
                  } else {
                      //We found messages!
                      self.messages = objects;
                      [self.tableView reloadData];
                      NSLog(@"Retrieved %lu messages", (unsigned long)[self.messages count]);
                  }
    }];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    // Return the number of rows in the section.
    return [self.messages count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Configure the cell...

    PFObject *message = [self.messages objectAtIndex:indexPath.row];
    cell.textLabel.text = [message objectForKey:@"senderName"];

    NSString *fileType = [message objectForKey:@"fileType"];
    if ([fileType isEqualToString:@"image"]) {
        cell.imageView.image = [UIImage imageNamed:@"icon_image"];
    } else {
        cell.imageView.image = [UIImage imageNamed:@"icon_video"];
    }

    return cell;
}

#pragma mark - Table View Delegate

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.selectedMessage = [self.messages objectAtIndex:indexPath.row];
    NSString *fileType = [self.selectedMessage objectForKey:@"fileType"];
    if ([fileType isEqualToString:@"image"]) {
        [self performSegueWithIdentifier:@"showImage" sender:self];
         }
         else { //filetype is video
             PFFile *videoFile = [self.selectedMessage objectForKey: @"file"];
             NSURL *fileUrl = [NSURL URLWithString:videoFile.url];
             self.moviePlayer.contentURL = fileUrl;
             [self.moviePlayer prepareToPlay];


             // Add it to the view controller
             [self.view addSubview:self.moviePlayer.view];
             [self.moviePlayer setFullscreen:YES animated:YES];

    }

    // Delete it!
    NSMutableArray *recipientIds = [NSMutableArray arrayWithArray:[self.selectedMessage objectForKey:@"recipientIds"]];
    NSLog(@"Recipients: %@", recipientIds);

    if ([recipientIds count] == 1) {
        //Last recipient - delete!
        [self.selectedMessage deleteInBackground];
    } else {

        //Remove the recipient!
        [recipientIds removeObject:[[PFUser currentUser] objectId]];
        [self.selectedMessage setObject:recipientIds forKey:@"recipientIds"];
        [self.selectedMessage saveInBackground];
    }
}

- (IBAction)logout:(id)sender {

    [PFUser logOut];
    [self performSegueWithIdentifier:@"showLogin" sender:self];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"showLogin"]) {
        [segue.destinationViewController setHidesBottomBarWhenPushed:YES];
    }
    else if  ([segue.identifier isEqualToString:@"showImage"]) {
        [segue.destinationViewController setHidesBottomBarWhenPushed:YES];
        ImageViewController *imageViewController = (ImageViewController *)segue.destinationViewController;
        imageViewController.message = self.selectedMessage;
    }

}
@end

Any help would be greatly appreciated! I can't seem to figure this out and it's, literally, bugging me!

6 Answers

try setting an exception breakpoint by going to debug -> breakpoints ->create exception breakpoint. This should pinpoint the line of code that is code that is throwing that error.

create exception breakpoint, check. Then run the code again and try to send a video?

came back with this line: if (self.image == nil && [self.videoFilePath length] == 0) which is right before ```{ UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Try again!" message:@"Please capture or select a photo/video to share!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [alertView show]; [self presentViewController:self.imagePicker animated:NO completion:nil]; } else { [self uploadMessage];

    [self.tabBarController setSelectedIndex:0];
}

``` However, I've tried commenting out this whole block and the error still occurs!

I apologize for the above formatting, unfortunately, Treehouse Forum is not letting me edit the answer and instead returning me to a page that "cannot be found"

hmm there could be an issue with that video file path then. whats your code look like where you set that file path property?

Here's my header file, where I set the file path property. (By the way, thank you so much for the help Stone!):

#import <UIKit/UIKit.h>
#import <Parse/Parse.h>

@interface CameraViewController : UITableViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>

@property (nonatomic, strong) UIImagePickerController *imagePicker;
@property (nonatomic, strong) UIImage *image;
@property (nonatomic, strong) NSString *videoFilePath;
@property (nonatomic, strong) NSArray *friends;
@property (nonatomic, strong) PFRelation *friendsRelation;
@property (nonatomic, strong) NSMutableArray *recipients;

- (IBAction)cancel:(id)sender;
- (IBAction)send:(id)sender;

- (void)uploadMessage;
- (UIImage *)resizeImage:(UIImage *)image toWidth:(float)width andHeight:(float)height;

@end

but where do you actually set its value in your implementation. Probably in your imagepicker didFinishPickingMedia or whatever the method is called. post the code for that

I believe that is in the code I posted in the original post:

    else {
        // A video was taken/selected
        self.videoFilePath = CFBridgingRelease([[info objectForKey:UIImagePickerControllerMediaURL] path]);
        if (self.imagePicker.sourceType == UIImagePickerControllerSourceTypeCamera) {
            //save the video!
            if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(self.videoFilePath)) {
            UISaveVideoAtPathToSavedPhotosAlbum(self.videoFilePath, nil, nil, nil);
            }

I figured it out! I had to replace

self.videoFilePath = CFBridgingRelease([[info objectForKey:UIImagePickerControllerMediaURL] path]);

with self.videoFilePath = (__bridge NSString *)([[info objectForKey:UIImagePickerControllerMediaURL] path]);

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Sorry about your frustration - you ran into a bug on iOS 7. A bug with the API itself, it seems! Your solution seems solid, but also check out the Teacher Notes on the video page.

Ah okay, well good to know! Thank you for confirming I was on the right track :)

I think i may have a similar problem in that my video just won't save causing the app to freeze when i press the 'use' button on the camera screen Here's my code, would be great if anyone could help Thanks Ben Jakuben in advance!

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    if ([mediaType isEqualToString:(NSString *) kUTTypeImage]) {
        // a photo was selected!
        self.image = [info objectForKey:UIImagePickerControllerOriginalImage];
        if (self.imagePicker.sourceType == UIImagePickerControllerSourceTypeCamera) {
            // save the image
            UIImageWriteToSavedPhotosAlbum(self.image, nil, nil, nil);
        }

        }
        else {
            // a video was taken or selected

           NSURL *imagePickerURL = [info objectForKey:UIImagePickerControllerMediaURL];
           self.videoFilePath = [imagePickerURL path];

           if (self.imagePicker.sourceType == UIImagePickerControllerSourceTypeCamera) {
                // save the video
                if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(self.videoFilePath)){

                UISaveVideoAtPathToSavedPhotosAlbum(self.videoFilePath, nil, nil, nil);
                }
            }

}
    [self dismissViewControllerAnimated:YES completion:nil];
}

Thanks Nicolai , your solution works!