In this recipe, we will learn how to use the device camera to capture the media.
Open the ImagePickerApp
project that we created in the previous recipe.
Note
The camera functionality is not available on iOS Simulator. This example can only run on the device. Refer to Chapter 14, Deploying, for more information.
Perform the following steps:
In the ViewDidLoad method of the controller class, replace
this.imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;
with the following code block:if (UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)) { this.imagePicker.SourceType = UIImagePickerControllerSourceType.Camera; } else { this.imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; }
In the
FinishedPickingMedia
handler, add the following code before the dismissal of the image picker:pickedImage.SaveToPhotosAlbum((s, error) => { if (null != error) { ...