UIImagePickerController Camera Source Problem

2019-05-30 21:50发布

问题:

Ok here is the code that I wrote to display the UIImagePickerController in the camera source. I just declared the myPhotopicker in the header for the property and retain it. Synthesized it in the main code file. Then calling the picker I wrote the code below:

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        if (myPhotopicker==nil) { 
            myPhotopicker = [[UIImagePickerController alloc] init];
            myPhotopicker.delegate = self; 
        }// create once!

        myPhotopicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        [self presentModalViewController:myPhotopicker animated:NO];
}

Upon calling it, there are a few things that is weird happening to the app.

  1. Sometimes, when there are many apps running in the background (iPhone4), the app would fail to load the camera and crash the app. Though it will load CameraRoll/PhotoAlbums without problem.

  2. If the camera view is able to load (when there are less apps running in the background), tapping the Cancel button on the camera view results in the app rebooting itself (where the Default.png image is shown quickly, and back to the main page - like when we started the app).

I have been trying to figure out this problem, but not sure what to do... pls help.. Thanks.

回答1:

here is the complete code of image pickercontrol try too find solu. here.

http://www.icodeblog.com/2009/07/28/getting-images-from-the-iphone-photo-library-or-camera-using-uiimagepickercontroller/

Regards,

Shyam Parmar



回答2:

Rather than your 'create once' logic try creating and releasing each time.

if ([UIImagePickerController  isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
     myPhotopicker = [[UIImagePickerController alloc] init];
     myPhotopicker.delegate = self;
     myPhotopicker.sourceType = UIImagePickerControllerSourceTypeCamera;
     [self presentModalViewController:myPhotopicker animated:NO];
     [myPhotopicker release];
}

You should also implement the delegate to remove the modal view controller from view when it is dismissed (if you haven't already).

You should also check that the current class conforms to the UINavigationConrollerDelegate protocol.