user552987
user552987

Reputation: 1

Make iphone camera as a magnifying lens

I have an application called magnifying lens .Here I need to start the camera at the time of appliaction starts itself.How can I possible to start the camera while starting the app?

I have the camera active code here

    // Create image picker controller
  UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

  // Set source to the camera
    imagePicker.sourceType =  UIImagePickerControllerSourceTypeCamera;

  // Delegate is self
    imagePicker.delegate = self;

  // Allow editing of image ?
    imagePicker.allowsImageEditing = NO;

  // Show image picker
    [self presentModalViewController:imagePicker animated:YES]; 

But I don't know where to place this code for start the camera at the time when the application starts.I put the code in the viewdidLoad method .But it didn't give me the desired result.

I am very new to this if you can suggest me an idea it will be very useful to me.

Thanks in advance Priya

Upvotes: 0

Views: 530

Answers (2)

Rahul Vyas
Rahul Vyas

Reputation: 28720

@Priya Ok I solved the issue. Put your code in viewDidAppear method. Implement the method on mainviewController. Here is what I did added Protocols in the interface file like this @interface MainViewController : UIViewController <FlipsideViewControllerDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate > and here is the viewDidAppear method

- (void)viewDidAppear:(BOOL)animated {

    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

        // Set source to the camera
    imagePicker.sourceType =  UIImagePickerControllerSourceTypePhotoLibrary;

        // Delegate is self
    imagePicker.delegate = self;

        // Allow editing of image ? //Deprecated
    imagePicker.allowsImageEditing = NO;

        //Use this instead
    imagePicker.allowsEditing = NO;
        // Show image picker
    [self presentModalViewController:imagePicker animated:YES]; 
}

Upvotes: 0

Rahul Vyas
Rahul Vyas

Reputation: 28720

@ Priya,

Where did you put that code? in app delegate the code won't work. first add a viewController's view to window. then in that view controller's viewDidLoad method put your code. Let me know your feedback

Upvotes: 1

Related Questions