Reputation: 51
Is it possible to update this code to run in the simulator? Right now the app Im working with crashes when it reaches this point in the code. Is there an nslog statement we could add to allow me to test this feature? I need to test simultaneously on my iPad and the simulator but the simulator crashes when I reach this code.
- (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];
}
}];
});
}
For instance here is the method that allows testing for UIImage picker however I am using 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];
}
Upvotes: 2
Views: 900
Reputation: 3767
No you can't use the camera in the simulator. It will crash when trying to load the camera and the hardware is not there. You need to use a device for all of those features. If you just need the camera, the iPod touch is a great solution.
Upvotes: 4