Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

Patrick Serrano
Patrick Serrano
13,834 Points

Error when setting videoFilePath in Saving the Media chapter of Build a Self-Destructing Messaging App

I'm running into a strange issue in the Saving the Media chapter of Build a Self-Destructing Messaging App.

When writing the following line of code in my project:

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

Xcode seems to be using the wrong path method. When I option click on the method I get this pop-up:

But when I download the project files, or try calling path in another project I get this pop-up when option clicking path:

Does anyone have any idea what's going on here?

I am having this same issue. I've tried Ben's solution below, but it hasn't worked for me.

The video is not saving to the Photo Album as well like in the video. The app crashes. Here's the console log:

 2013-10-07 17:38:53.220 Ribbit[2956:680b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString CGImage]: unrecognized selector sent to instance 0x16d7a4b0'

*** First throw call stack: (0x2e675f53 0x38a4e6af 0x2e6798e7 0x2e6781d3 0x2e5c7598 0x34cf8f01 0x34db9e3b 0x38f31d7b 0x38f38297 0x38f3809b 0x38f38d15 0x38f38f8d 0x39073dbf 0x39073c84) libc++abi.dylib: terminating with uncaught exception of type NSException

Also, I'm getting a warning on this line:

 UIImageWriteToSavedPhotosAlbum(self.videoFilePath, nil, nil, nil);

Xcode is referring to "self.videoFilePath" part of that line. The warning says "Incompatible pointer types passing 'NSString' to parameter of type 'NSImage'.

Is this referring to the properties in the CameraViewController.h?

@property (strong, nonatomic) UIImage *image;
@property (strong, nonatomic) NSString *videoFilePath;

Kinda sucks, but I can't continue the tutorial because of this.

To add to the above comment. It's only crashing on the device which actually uses the camera and not in the simulator.

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Can you paste in the code where you are setting the videoFilePath property?

Unfortunately, I'm also unable to get the video to save. Everything builds just fine, but I cannot get it to appear in my media library.

Here is the code I'm using below

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
    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 ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
        self.image = [info objectForKey:UIImagePickerControllerOriginalImage];
        if (self.imagePicker.sourceType == UIImagePickerControllerSourceTypeCamera) {
            if(UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(self.videoFilePath)) {
            UISaveVideoAtPathToSavedPhotosAlbum(self.videoFilePath, nil, nil, nil);
            }
        }

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

}

Nevermind, I found my problem. had the random "if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) { self.image = [info objectForKey:UIImagePickerControllerOriginalImage];" in my else statement

That's what happens when you're careless about copying and pasting.

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Heh - glad you got it working! Happens to all of us. :)

5 Answers

Patrick Serrano
Patrick Serrano
13,834 Points

Ben,

Even if I re-write the entire line, every time I try to call path it shows as a CGPathRef. It’s weird because it only happens in this project. The Xcode fix-it suggests this change:

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

But since it doesn’t seem to be calling the right method, I didn’t that that would be an appropriate solution.

You can download the project here. (I should note, that I am building against the iOS7 SDK beta. I don’t think this is the problem, because I have a half dozen projects built against the iOS 7 SDK beta which can call the correct path method with no problems.)

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Strange...it does seem to be because of the iOS 7 SDK. I just opened it in Xcode 5 and got the same behavior you described. I was able to get around it by breaking that line apart, like this:

NSURL *imagePickerURL = [info objectForKey:UIImagePickerControllerMediaURL];
self.videoFilePath = [imagePickerURL path];
Patrick Serrano
Patrick Serrano
13,834 Points

Ben thanks a lot for helping to find a solution. I’m thinking about filling a bug with Apple about that, because it doesn’t seem like the expected behavior.

Ben Jakuben
Ben Jakuben
Treehouse Teacher

I agree - it shouldn't be working that way! Filing a bug would be a good idea. :)

It would be useful to post a note about this issue on Xcode 5 and iOS 7 on that video.

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Very strange...can you post your whole code in here? If you delete that call to path and start typing it again, what does autocomplete show for you?

Patrick Serrano
Patrick Serrano
13,834 Points

Any Ideas? I'd really like to avoid starting over if at all possible. Thanks a ton.

Thanks for the update. It breaks done when i add the new code for ios7 though. This is error I get: "Warning: Attempt to present <UIImagePickerController: 0x10a1bbe40> on <UITabBarController: 0x109e19a50> while a presentation is in progress!"

I have successfully got the amended code to work; however, the video doesn't show in camera roll, has anyone else had this issue?

same problem, cant find video on my camera roll.

Do you use a developer account?