#pragma warning disable CS4014
        public override async void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Sanity check for permissions - if we're here, it should be safe
            bool hasPerm = await AppUtils.AuthorizeCamera();

            if (!hasPerm)
            {
                AppUtils.ShowSimpleDialog(this, "Requires Camera", "Please grant OurPlace camera access in the system settings to complete this task!", "Ok");
                NavigationController.PopViewController(true);
                return;
            }

            if (thisTask == null)
            {
                AppUtils.ShowSimpleDialog(this, "ERROR", "Error loading task data", "Ok");
                NavigationController.PopViewController(true);
                return;
            }

            folderName = Common.LocalData.Storage.GetCacheFolder(thisActivity.Id.ToString());

            devices = new List <AVCaptureDevice>(discSession.Devices);
            SwapCameraButton.Enabled &= (devices != null && devices.Count != 0);

            if (thisTask.TaskType.IdName == "MATCH_PHOTO")
            {
                // Load target photo
                OverlayImageView.Alpha = 0.6f;

                string localRes = Common.LocalData.Storage.GetCacheFilePath(
                    thisTask.JsonData,
                    thisActivity.Id,
                    ServerUtils.GetFileExtension(thisTask.TaskType.IdName));

                ImageService.Instance.LoadFile(localRes).Into(OverlayImageView);
            }
            else if (thisTask.TaskType.IdName == "TAKE_VIDEO")
            {
                isMovie = true;
                ImageService.Instance.LoadCompiledResource("RecordButton").IntoAsync(ShutterButton);

                hasPerm = await AppUtils.AuthorizeMic();

                if (!hasPerm)
                {
                    AppUtils.ShowSimpleDialog(this, "Requires Microphone", "Please grant OurPlace microphone access in the system settings to complete this task!", "Ok");
                    NavigationController.PopViewController(true);
                    return;
                }
            }
            else
            {
                OverlayImageView.Alpha = 0;
            }

            SetupLiveCameraStream();
        }
        public override async void ViewDidLoad()
        {
            base.ViewDidLoad();

            fileName = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".m4a";

            if (!createMode)
            {
                if (thisTask == null || thisActivity == null)
                {
                    AppUtils.ShowSimpleDialog(this, "ERROR", "Error loading task data", "Ok");
                    NavigationController.PopViewController(true);
                    return;
                }

                TaskDescriptionLabel.Text = thisTask.Description;

                folderName = Common.LocalData.Storage.GetCacheFolder(thisActivity.Id.ToString());
            }
            else
            {
                // set up for recording to 'listen to audio' tasks
                folderName = Common.LocalData.Storage.GetCacheFolder("created");
            }

            filePath = Path.Combine(folderName, fileName);


            // Sanity check for permissions - if we're here, it should be safe
            bool hasPerm = await AppUtils.AuthorizeMic();

            if (!hasPerm)
            {
                AppUtils.ShowSimpleDialog(this, "Requires Microphone", "Please grant OurPlace microphone access in the system settings to record audio clips!", "Ok");
                NavigationController.PopViewController(true);
                return;
            }

            // Set up audio recording session
            audioSession = AVAudioSession.SharedInstance();
            NSError err = audioSession.SetCategory(AVAudioSessionCategory.PlayAndRecord);

            if (err != null)
            {
                Console.WriteLine("ERROR setting up audio session: " + err.LocalizedDescription);
                return;
            }

            err = audioSession.SetActive(true);
            if (err != null)
            {
                Console.WriteLine("ERROR activating audio session: " + err.LocalizedDescription);
                return;
            }

            //set up the NSObject Array of values that will be combined with the keys to make the NSDictionary
            NSObject[] values = new NSObject[]
            {
                NSNumber.FromFloat(16000.0f),                                   //Sample Rate
                NSNumber.FromInt32((int)AudioToolbox.AudioFormatType.MPEG4AAC), //AVFormat
                NSNumber.FromInt32(1),                                          //Channels
                NSNumber.FromInt32(16),                                         //PCMBitDepth
                NSNumber.FromBoolean(false),                                    //IsBigEndianKey
                NSNumber.FromBoolean(false)                                     //IsFloatKey
            };

            //Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary
            NSObject[] keys = new NSObject[]
            {
                AVAudioSettings.AVSampleRateKey,
                AVAudioSettings.AVFormatIDKey,
                AVAudioSettings.AVNumberOfChannelsKey,
                AVAudioSettings.AVLinearPCMBitDepthKey,
                AVAudioSettings.AVLinearPCMIsBigEndianKey,
                AVAudioSettings.AVLinearPCMIsFloatKey
            };

            //Set Settings with the Values and Keys to create the NSDictionary
            settings = NSDictionary.FromObjectsAndKeys(values, keys);

            //Set recorder parameters
            recorder = AVAudioRecorder.Create(NSUrl.FromFilename(filePath), new AudioSettings(settings), out error);

            recorder.PrepareToRecord();
        }
        private async void StartTask(AppTask taskData)
        {
            switch (taskData.TaskType.IdName)
            {
            case "DRAW":
            case "DRAW_PHOTO":
                DrawingViewController drawingController = Storyboard.InstantiateViewController("DrawingController") as DrawingViewController;
                drawingController.StartTask(DisplayedActivity, taskData, TaskResultReturned, NavigationController);

                // check to see if should draw on previous task's result
                if (taskData.JsonData.StartsWith("TASK::", StringComparison.OrdinalIgnoreCase))
                {
                    int id = -1;
                    int.TryParse(taskData.JsonData.Substring(6), out id);
                    string[] paths = JsonConvert.DeserializeObject <string[]>(
                        ((TaskViewSource)TableView.Source).GetWithId(id)?.CompletionData.JsonData);

                    if (paths != null && paths.Length > 0)
                    {
                        drawingController.previousImage = paths[0];
                    }
                }

                break;

            case "LISTEN_AUDIO":
                ResultMediaViewerController listenAudioController = Storyboard.InstantiateViewController("MediaViewerController") as ResultMediaViewerController;
                listenAudioController.FilePath     = GetCacheFilePath(taskData.JsonData, DisplayedActivity.Id, ServerUtils.GetFileExtension(taskData.TaskType.IdName));;
                listenAudioController.Task         = taskData;
                listenAudioController.DeleteResult = null;
                NavigationController.PushViewController(listenAudioController, true);

                // Mark as complete
                TaskResultReturned(null, taskData.Id);

                break;

            case "MAP_MARK":
                MapMarkingViewController mapMarkController = Storyboard.InstantiateViewController("MapMarkController") as MapMarkingViewController;
                mapMarkController.StartTask(DisplayedActivity, taskData, TaskResultReturned, NavigationController);
                break;

            case "LOC_HUNT":
                LocationHuntViewController locHuntController = Storyboard.InstantiateViewController("LocationHuntController") as LocationHuntViewController;
                locHuntController.StartTask(DisplayedActivity, taskData, TaskResultReturned, NavigationController);
                break;

            case "ENTER_TEXT":
                EnterTextViewController textController = Storyboard.InstantiateViewController("EnterTextController") as EnterTextViewController;
                textController.StartTask(DisplayedActivity, taskData, TaskResultReturned, NavigationController);
                break;

            case "MULT_CHOICE":
                MultipleChoiceController mcController = Storyboard.InstantiateViewController("MultipleChoiceController") as MultipleChoiceController;
                mcController.StartTask(DisplayedActivity, taskData, TaskResultReturned, NavigationController);
                break;

            case "TAKE_VIDEO":
                bool hasMicPerms = await AppUtils.AuthorizeMic();

                if (!hasMicPerms)
                {
                    AppUtils.ShowSimpleDialog(this, "Requires Microphone", "Please grant OurPlace microphone access in the system settings to complete this task!", "Ok");
                    return;
                }
                goto case "TAKE_PHOTO";     // eew C# why u do dis

            case "MATCH_PHOTO":
            case "TAKE_PHOTO":
                bool hasCamPerms = await AppUtils.AuthorizeCamera();

                if (!hasCamPerms)
                {
                    AppUtils.ShowSimpleDialog(this, "Requires Camera", "Please grant OurPlace camera access in the system settings to complete this task!", "Ok");
                    return;
                }
                CameraViewController camController = Storyboard.InstantiateViewController("PhotoTaskViewController") as CameraViewController;
                camController.StartTask(DisplayedActivity, taskData, TaskResultReturned, NavigationController);
                break;

            case "REC_AUDIO":
                hasMicPerms = await AppUtils.AuthorizeMic();

                if (!hasMicPerms)
                {
                    AppUtils.ShowSimpleDialog(this, "Requires Microphone", "Please grant OurPlace microphone access in the system settings to complete this task!", "Ok");
                    return;
                }
                RecordAudioController audioController = Storyboard.InstantiateViewController("RecordAudioController") as RecordAudioController;
                audioController.StartTask(DisplayedActivity, taskData, TaskResultReturned, NavigationController);
                break;

            case "SCAN_QR":
                StartScanning(taskData);
                break;

            default:
                Console.WriteLine("Unknown task type: " + taskData.TaskType.IdName);
                break;
            }
        }