是否可以更新此代码以在模拟器中运行?现在,当应用程序到达代码中的这一点时,我正在处理的应用程序就会崩溃。我们是否可以添加 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];
}
最佳答案
不,你不能在模拟器中使用相机。当尝试加载相机且硬件不存在时,它会崩溃。您需要使用设备来实现所有这些功能。如果您只需要相机,iPod touch 是一个很好的解决方案。
关于ios - 在 iOS 模拟器中测试 iPhone 相机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29724653/