views:

802

answers:

1

Hello all, I am developing an application which uses both video recording and photo shoting.So i want to show buttons according to os for this i implement these methods.It's working fine when i build for OS 3.1 but when i build for OS 3.0 it shows errors

here are the methods

    if ([self videoRecordingAvailable])
    {
        imagePickerController.sourceType =  UIImagePickerControllerSourceTypeCamera;
        imagePickerController.allowsImageEditing = YES;
        imagePickerController.allowsEditing = YES;
        imagePickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;
        imagePickerController.videoMaximumDuration = 60.0f; // Length for video recording in seconds
        imagePickerController.mediaTypes = [NSArray arrayWithObjects:@"public.movie", nil];
        imagePickerController.showsCameraControls=YES;      
        [self.navigationController presentModalViewController:imagePickerController animated:YES];          
    }


- (BOOL) videoRecordingAvailable
{
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) return NO;
return [[UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera] containsObject:@"public.movie"];
}

the errors are

error: request for member 'allowsEditing' in something not a structure or union
error: request for member 'videoQuality' in something not a structure or union
error: 'UIImagePickerControllerQualityTypeHigh' undeclared (first use in this function)
 (Each undeclared identifier is reported only once for each function it appears in.)
error: request for member 'videoMaximumDuration' in something not a structure or union
error: request for member 'showsCameraControls' in something not a structure or union

how do i solve this issue?

+1  A: 

The problem is that the video capture has been added in 3.1, which means that the image picker from 3.0 does not support any of the video properties and methods (see the documentation and pay attention to the Availability sections).

As for the solution, I guess you could try using the message syntax instead of the dot syntax:

[picker setShowsCameraControls:YES];

This will give you warnings though (when compiled for 3.0 and older), and you have to be careful not to do it on older devices, because you’ll get an unknown selector exception. Or you can call the selector dynamically, which will get rid of the warnings and you can also check if the selector is supported first:

SEL msg = @selector(setShowsCameraControls:);
if ([picker respondsToSelector:msg])
    [picker performSelector…];

There are already several questions about writing for different OS versions.


Responding to comments: I think the main problem is that you are blindly pasting the code without understading it. Don’t do that. Sit and think about what the code does, until you understand each and every line. Now to explain your problem more thoroughly:

The Image Picker in 3.0 has no video controls, since it can’t record video. Therefore when you try to compile a code such as picker.showsCameraControls, the compiler complains: There is no showsCameraControls property in the Image Picker class, that has only been added in 3.1.

But there is a way around that, you can use the message syntax ([foo setBar:…]) instead of the dot syntax (foo.bar=…). If the foo object has no setBar method, the compiler will warn you, but the code will compile. Now let’s use the message syntax to set the camera controls:

[picker setShowsCameraControls:YES];

When you compile this code for 3.1, it will compile without warning and run without error. When you compile for 3.0, you will get a warning from the compiler and if you run the code, it will fail (since there really is no showsCameraControls property). But that is not a problem, since you can only decide to run the fragile code if the OS supports it:

BOOL videoSupported = [picker respondsToSelector:@selector(setShowsCameraControls:)];
if (videoSupported) {
    [picker setShowsCameraControls:YES];
    // set all the other video properties
} else {
    // do what makes sense without video support
}

This will work, but you’ll still get compiler warnings on 3.0. Now it depends on your default build target. If you build for 3.1, the warnings will disappear and the code should work on 3.0 just fine.

zoul
can you complete the code? I mean change my code according to you please....
Rahul Vyas
No, because I honestly think it’s best for you to figure it out yourself now. At least until you run into a real problem again.
zoul
but it's not working.Here what i tried[imagePickerController setAllowsImageEditing:YES]; SEL msg = @selector(setVideoQuality:); if ([imagePickerController respondsToSelector:msg]) [imagePickerController performSelector:msg withObject:self afterDelay:0];But it's still showing error
Rahul Vyas
actually i'm unable to figure that how do i set values...What is the mean of this line [picker performSelector…];how do i set this [imagePickerController setVideoQuality:UIImagePickerControllerQualityTypeHigh];
Rahul Vyas
now it shows warnings.But still en error on setVideoQuality...please tell me the performselector use...
Rahul Vyas
I guess that’s because you’re missing the `UIImagePickerControllerQualityTypeHigh` constant. You can try to replace it with a zero. It’s a hack, but I think it will do for your purposes.
zoul
and what about this BOOL compatible = UIVideoAtPathIsCompatibleWithSavedPhotosAlbum([MovieUrl path]);
Rahul Vyas
it's also showing errorUndefined symbols: "_UIVideoAtPathIsCompatibleWithSavedPhotosAlbum", referenced from: -[VideoAndImageView imagePickerController:didFinishPickingMediaWithInfo:] in VideoAndImageView.old: symbol(s) not foundcollect2: ld returned 1 exit status
Rahul Vyas
No reasonable idea there. I think you should take a look at those two links to questions about writing backwards-compatible applications, you might find a solution there.
zoul