是否可以更新此代码以在模拟器中运行?现在,当我在代码中达到这一点时,应用程序正在处理崩溃。是否有我们可以添加的nslog语句允许我测试此功能?我需要在iPad和模拟器上同时测试,但是当我到达此代码时模拟器崩溃。
- (void)snapStillImage //this is being called on did load
{
dispatch_async([self sessionQueue], ^{
// Update the orientation on the still image output video connection before capturing.
[[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] setVideoOrientation:[[(AVCaptureVideoPreviewLayer *)[[self previewView] layer] connection] videoOrientation]];
// Flash set to Auto for Still Capture
[ViewController5 setFlashMode:AVCaptureFlashModeAuto forDevice:[[self videoDeviceInput] device]];
// Capture a still image.
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
if (imageDataSampleBuffer)
{
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
photo.image = [[UIImage alloc] initWithData:imageData];
[[[ALAssetsLibrary alloc] init] writeImageToSavedPhotosAlbum:[photo.image CGImage] orientation:(ALAssetOrientation)[photo.image imageOrientation] completionBlock:nil];
[self uploadPhoto];
}
}];
});
}
例如,这里是允许测试UIImage选择器的方法,但我正在使用AVCam ......
-(void)takePhoto {
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
#if TARGET_IPHONE_SIMULATOR
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
#else
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
#endif
imagePickerController.editing = YES;
imagePickerController.delegate = (id)self;
[self presentModalViewController:imagePickerController animated:YES];
}
答案 0 :(得分:3)
不能在模拟器中使用相机。尝试加载相机并且硬件不存在时会崩溃。您需要将设备用于所有这些功能。如果您只需要相机,iPod touch是一个很好的解决方案。