2015-02-06 35 views
-1

我一直在试图设置一个小的iOS方法,当用户打开应用程序时自动拍照。经过大量的研究,我终于找到了这个iOS taking photo programmatically,并且在我从苹果中发现了这个之后,我再次发现了这个https://developer.apple.com/library/ios/samplecode/AVCam/Introduction/Intro.html有人可以帮我开始设置一个方法captureStillImageAsynchronouslyFromConnection:completionHandler: 我不希望来自这个用户的任何交互。感谢处理captureStillImageAsynchronouslyFromConnection:completionHandler:

+0

为什么你会需要捕获为异步? – 2015-02-06 05:06:50

+0

我想以编程方式拍摄照片,无需任何用户输入 – 2015-02-06 06:15:49

+0

您不需要为此异步捕获图像......只需创建一个uiimagepicker,如第二回答iOS中所述,以编程方式拍照并调用takePicture:http: //stackoverflow.com/a/23312505/2274694 – 2015-02-06 06:18:00

回答

1

即使你似乎想要做的异步调用,并使用AVFoundation,我还是在这种情况下,建议只需使用UIImagePickerController,例如:

- (void)viewDidLoad { 

    [super viewDidLoad]; 

    // If the device has a camera... 
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 

     // Create an image picker 
     UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; 
     imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; 
     imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront; 
     imagePickerController.showsCameraControls = NO; 
     imagePickerController.delegate = self; 

     [self presentViewController:imagePickerController animated:YES completion:^{ 

      // And take the picture after a short delay 
      // to give the view and image picker time to get 
      // ready 
      [self performSelector:@selector(takepic:) withObject:imagePickerController afterDelay:2]; 
     }]; 
    } 
} 

// Automatically take the picture using the 
// image picker passed in as a parameter 
- (void)takepic:(UIImagePickerController*)imagePickerController { 
    [imagePickerController takePicture]; 
} 

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; 

    // ... Do whatever with the image ... 

    [picker dismissViewControllerAnimated:YES completion:nil]; 
} 
+0

非常酷。谢谢 – 2015-02-06 20:41:24

+0

@mobonus没问题:) – 2015-02-06 20:49:08