Book Image

iOS Development with Xamarin Cookbook

By : Dimitrios Tavlikos (USD)
Book Image

iOS Development with Xamarin Cookbook

By: Dimitrios Tavlikos (USD)

Overview of this book

Table of Contents (22 chapters)
iOS Development with Xamarin Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Capturing media with the camera


In this recipe, we will learn how to use the device camera to capture the media.

Getting ready

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.

How to do it...

Perform the following steps:

  1. 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;
    }
  2. In the FinishedPickingMedia handler, add the following code before the dismissal of the image picker:

    pickedImage.SaveToPhotosAlbum((s, error) => {
      if (null != error)
      {
      ...