public bool IsCameraAuthorized()
        {
            AVAuthorizationStatus authStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);

            if (authStatus == AVAuthorizationStatus.Authorized)
            {
                // do your logic
                return(true);
            }
            else if (authStatus == AVAuthorizationStatus.Denied)
            {
                // denied
                return(false);
            }
            else if (authStatus == AVAuthorizationStatus.Restricted)
            {
                // restricted, normally won't happen
                return(false);
            }
            else if (authStatus == AVAuthorizationStatus.NotDetermined)
            {
                // not determined?!
                return(false);
            }
            else
            {
                return(false);
                // impossible, unknown authorization status
            }
        }
Esempio n. 2
0
        public void RefcountTest()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(7, 0))
            {
                Assert.Ignore("This test uses iOS 7 API");
            }

            // Bug #27205

            var auth = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);

            switch (auth)
            {
            case AVAuthorizationStatus.Restricted:
            case AVAuthorizationStatus.Denied:
            case AVAuthorizationStatus.NotDetermined:
                Assert.Inconclusive("This test requires video recording permissions.");
                return;
            }

            using (var captureSession = new AVCaptureSession()) {
                using (var videoDevice = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Video)) {
                    foreach (var format in videoDevice.Formats)
                    {
                        for (int i = 0; i < 10; i++)
                        {
                            using (var f = format.FormatDescription) {
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Checks if access to the Camera is granted, and if not (Denied), shows an error message.
        /// </summary>
        public async Task <bool> EnsureHasCameraAccess()
        {
            var status = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);

            if (status == AVAuthorizationStatus.Denied)
            {
                var alert = UIAlertController.Create(CustomCameraAccessDeniedErrorTitle ?? "picker.camera-access-denied.title".Translate(),
                                                     CustomCameraAccessDeniedErrorMessage ?? "picker.camera-access-denied.message".Translate(),
                                                     UIAlertControllerStyle.Alert);

                alert.AddAction(UIAlertAction.Create("picker.navigation.cancel-button".Translate("Cancel"), UIAlertActionStyle.Cancel, null));
                alert.AddAction(UIAlertAction.Create("picker.navigation.settings-button".Translate("Settings"), UIAlertActionStyle.Default, (action) => UIApplication.SharedApplication.OpenUrl(NSUrl.FromString(UIApplication.OpenSettingsUrlString))));

                await PresentViewControllerAsync(alert, true);

                return(false);
            }
            else if (status == AVAuthorizationStatus.NotDetermined)
            {
                return(await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video) &&
                       await EnsureHasPhotosPermission());
            }

            return(await EnsureHasPhotosPermission());
        }
Esempio n. 4
0
        public void Resume()
        {
            _sessionQueue.DispatchAsync(() =>
            {
                if (_isSessionRunning)
                {
                    Console.WriteLine("capture session: warning - trying to resume already running session");
                    return;
                }

                switch (_setupResult)
                {
                case SessionSetupResult.Success:
                    _notificationCenterHandler.AddObservers(Session);
                    Session.StartRunning();
                    _isSessionRunning = Session.Running;
                    break;

                case SessionSetupResult.NotAuthorized:
                    Console.WriteLine("capture session: not authorized");
                    DispatchQueue.MainQueue.DispatchAsync(() =>
                    {
                        var status = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);
                        _captureSessionDelegate.CaptureFailedSession(status);
                    });
                    break;

                case SessionSetupResult.ConfigurationFailed:
                    Console.WriteLine("capture session: configuration failed");
                    DispatchQueue.MainQueue.DispatchAsync(_captureSessionDelegate.DidFailConfiguringSession);
                    break;
                }
            });
        }
Esempio n. 5
0
        public void WillDisplayCameraCell(CameraCollectionViewCell cell)
        {
            SetupCameraCellIfNeeded(cell);

            if (cell is LivePhotoCameraCell liveCameraCell)
            {
                liveCameraCell.UpdateWithCameraMode(CaptureSettings.CameraMode);
            }

            if (_captureSession.PhotoCaptureSession != null)
            {
                //update live photos
                cell.UpdateLivePhotoStatus(_captureSession.PhotoCaptureSession.InProgressLivePhotoCapturesCount > 0,
                                           false);
            }

            //update video recording status
            var isRecordingVideo = _captureSession.VideoCaptureSession?.IsRecordingVideo ?? false;

            cell.UpdateRecordingVideoStatus(isRecordingVideo, false);

            //update authorization status if it's changed
            var status = AVCaptureDevice.GetAuthorizationStatus(AVAuthorizationMediaType.Video);

            if (cell.AuthorizationStatus != status)
            {
                cell.AuthorizationStatus = status;
            }

            //resume session only if not recording video
            if (!isRecordingVideo)
            {
                _captureSession.Resume();
            }
        }
Esempio n. 6
0
        public void Prepare(AVCaptureVideoOrientation captureVideoOrientation)
        {
            var status = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);

            if (status == AVAuthorizationStatus.NotDetermined)
            {
                _sessionQueue.Suspend();
                AVCaptureDevice.RequestAccessForMediaType(AVAuthorizationMediaType.Video, granted =>
                {
                    if (granted)
                    {
                        DispatchQueue.MainQueue.DispatchAsync(() =>
                        {
                            _captureSessionDelegate.CaptureGrantedSession(AVAuthorizationStatus.Authorized);
                        });
                    }
                    else
                    {
                        _setupResult = SessionSetupResult.NotAuthorized;
                    }

                    _sessionQueue.Resume();
                });
            }
            else if (status != AVAuthorizationStatus.Authorized)
            {
                _setupResult = SessionSetupResult.NotAuthorized;
            }

            _sessionQueue.DispatchAsync(() =>
            {
                ConfigureSession();
                UpdateVideoOrientation(captureVideoOrientation);
            });
        }
        private void InitSession()
        {
            try
            {
                //init capture session
                _AVSession = new AVCaptureSession();

                //check permissions
                var authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);
                if (authorizationStatus != AVAuthorizationStatus.Authorized)
                {
                    return;
                }

                //check capture camera
                var cameras = AVCaptureDevice.DevicesWithMediaType(AVMediaType.Video);
                var camera  = cameras.FirstOrDefault(d => d.Position == AVCaptureDevicePosition.Back);
                if (camera == null)
                {
                    return;
                }

                //add input to capture session
                _AVDeviceImput = new AVCaptureDeviceInput(camera, out NSError _);
                if (_AVSession.CanAddInput(_AVDeviceImput))
                {
                    _AVSession.AddInput(_AVDeviceImput);
                }
                else
                {
                    return;
                }

                //add output to camera session
                _MetadataObjectsQueue = new DispatchQueue("metadata objects queue");
                _AVMetadataOutput     = new AVCaptureMetadataOutput();
                if (_AVSession.CanAddOutput(_AVMetadataOutput))
                {
                    _AVSession.AddOutput(_AVMetadataOutput);
                }
                else
                {
                    return;
                }
                _AVMetadataOutput.SetDelegate(this, _MetadataObjectsQueue);

                //init the video preview layer and add it to the current view
                _AVVideoPeviewLayer = new AVCaptureVideoPreviewLayer(_AVSession);
                _AVVideoPeviewLayer.VideoGravity = AVLayerVideoGravity.ResizeAspectFill;
                _AVVideoPeviewLayer.Frame        = Bounds;
                this.Layer.AddSublayer(_AVVideoPeviewLayer);

                //start capture session
                StartSession(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine("IOS_SCAN | init error", ex);
            }
        }
Esempio n. 8
0
        private void Setup()
        {
            AVAuthorizationStatus authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);

            switch (authorizationStatus)
            {
            case AVAuthorizationStatus.NotDetermined: {
                AVCaptureDevice.RequestAccessForMediaType(AVMediaType.Video, new AVRequestAccessStatus(delegate(bool accessGranted) {
                        if (accessGranted)
                        {
                            SetupCapture();
                        }
                        else
                        {
                            Console.WriteLine("Access denied");
                        }
                    }));
                break;
            }

            case AVAuthorizationStatus.Authorized: {
                SetupCapture();
                break;
            }

            case AVAuthorizationStatus.Restricted: {
                Console.WriteLine("Access denied");
                break;
            }

            default: {
                break;
            }
            }
        }
Esempio n. 9
0
    public static void RequestCameraPermission(NSString mediaTypeToken, bool assert_granted = false)
    {
#if __MACCATALYST__
        // Microphone requires a hardened runtime entitlement for Mac Catalyst: com.apple.security.device.microphonee,
        // so just ignore these tests for now.
        NUnit.Framework.Assert.Ignore("Requires a hardened runtime entitlement: com.apple.security.device.microphone");
#endif // __MACCATALYST__

        if (AVCaptureDevice.GetAuthorizationStatus(mediaTypeToken) == AVAuthorizationStatus.NotDetermined)
        {
            if (IgnoreTestThatRequiresSystemPermissions())
            {
                NUnit.Framework.Assert.Ignore("This test would show a dialog to ask for permission to access the camera.");
            }

            AVCaptureDevice.RequestAccessForMediaType(mediaTypeToken, (accessGranted) =>
            {
                Console.WriteLine("Camera permission {0}", accessGranted ? "granted" : "denied");
            });
        }

        switch (AVCaptureDevice.GetAuthorizationStatus(AVMediaTypes.Video.GetConstant()))
        {
        case AVAuthorizationStatus.Restricted:
        case AVAuthorizationStatus.Denied:
            if (assert_granted)
            {
                NUnit.Framework.Assert.Fail("This test requires permission to access the camera.");
            }
            break;
        }
    }
        /// <summary>
        /// Determines whether the app has access to the camera. If the user has never been asked,
        /// the app requests access and awaits the user's response.
        /// </summary>
        /// <returns>True if the user has given the app access to the camera. False otherwise.</returns>
        async private Task <bool> HasCameraPermissions()
        {
            // GetAuthorizationStatus is an enum. See https://developer.xamarin.com/api/type/MonoTouch.AVFoundation.AVAuthorizationStatus/
            var authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);

            System.Diagnostics.Debug.WriteLine(authorizationStatus);

            // if user has not specified been asked for permissions
            if (authorizationStatus == AVAuthorizationStatus.NotDetermined)
            {
                System.Diagnostics.Debug.WriteLine("User has not been asked for access yet. Asking user...");

                // ask for access to camera
                await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video);

                // update authorizationStatus
                authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);

                AnalyticsService.TrackEvent(AnalyticsService.Event.CameraPermission, new Dictionary <string, string> {
                    { AnalyticsService.PropertyKey.Selection, authorizationStatus.ToString() }
                });

                System.Diagnostics.Debug.WriteLine("Asked user for permissions. Current authorizationStatus is... " + authorizationStatus);
            }

            return(authorizationStatus == AVAuthorizationStatus.Authorized);
        }
Esempio n. 11
0
        private CameraState _checkIfCameraIsAvailable()
        {
            var deviceHasCamera = UIImagePickerController.IsCameraDeviceAvailable(UIImagePickerControllerCameraDevice.Rear) ||
                                  UIImagePickerController.IsCameraDeviceAvailable(UIImagePickerControllerCameraDevice.Front);

            if (deviceHasCamera)
            {
                var authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);
                var userAgreedToUseIt   = authorizationStatus == AVAuthorizationStatus.Authorized;
                if (userAgreedToUseIt)
                {
                    return(CameraState.Ready);
                }
                else if (authorizationStatus == AVAuthorizationStatus.NotDetermined)
                {
                    return(CameraState.NotDetermined);
                }
                else
                {
                    //                            _show(NSLocalizedString("Camera access denied", comment:""), message:NSLocalizedString("You need to go to settings app and grant acces to the camera device to use it.", comment:""))
                    return(CameraState.AccessDenied);
                }
            }
            else
            {
                //                _show(NSLocalizedString("Camera unavailable", comment:""), message:NSLocalizedString("The device does not have a camera.", comment:""))
                return(CameraState.NoDeviceFound);
            }
        }
Esempio n. 12
0
        async Task RequestAccessForVideo()
        {
            var status = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);

            switch (status)
            {
            case AVAuthorizationStatus.NotDetermined:
                var granted = await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video);

                if (granted)
                {
                    _session.Running = true;
                }
                break;

            case AVAuthorizationStatus.Authorized:
                _session.Running = true;
                break;

            case AVAuthorizationStatus.Denied:
            case AVAuthorizationStatus.Restricted:
            default:
                break;
            }
        }
Esempio n. 13
0
    public static void RequestCameraPermission(NSString mediaTypeToken, bool assert_granted = false)
    {
        if (AVCaptureDevice.GetAuthorizationStatus(mediaTypeToken) == AVAuthorizationStatus.NotDetermined)
        {
            if (IgnoreTestThatRequiresSystemPermissions())
            {
                NUnit.Framework.Assert.Ignore("This test would show a dialog to ask for permission to access the camera.");
            }

            AVCaptureDevice.RequestAccessForMediaType(mediaTypeToken, (accessGranted) =>
            {
                Console.WriteLine("Camera permission {0}", accessGranted ? "granted" : "denied");
            });
        }

        switch (AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video))
        {
        case AVAuthorizationStatus.Restricted:
        case AVAuthorizationStatus.Denied:
            if (assert_granted)
            {
                NUnit.Framework.Assert.Fail("This test requires permission to access the camera.");
            }
            break;
        }
    }
Esempio n. 14
0
        void FireAVPermissionCompletionHandlerWithType(ClusterAVAuthorizationType mediaType)
        {
            AVAuthorizationStatus status = AVCaptureDevice.GetAuthorizationStatus(AVEquivalentMediaType(mediaType));

            if (_avPermissionCompletionHandler != null)
            {
                ClusterDialogResult userDialogResult   = ClusterDialogResult.Granted;
                ClusterDialogResult systemDialogResult = ClusterDialogResult.Granted;
                if (status == AVAuthorizationStatus.NotDetermined)
                {
                    userDialogResult   = ClusterDialogResult.Denied;
                    systemDialogResult = ClusterDialogResult.NoActionTaken;
                }
                else if (status == AVAuthorizationStatus.Authorized)
                {
                    userDialogResult   = ClusterDialogResult.Granted;
                    systemDialogResult = ClusterDialogResult.Granted;
                }
                else if (status == AVAuthorizationStatus.Denied)
                {
                    userDialogResult   = ClusterDialogResult.Granted;
                    systemDialogResult = ClusterDialogResult.Denied;
                }
                else if (status == AVAuthorizationStatus.Restricted)
                {
                    userDialogResult   = ClusterDialogResult.Granted;
                    systemDialogResult = ClusterDialogResult.ParentallyRestricted;
                }
                _avPermissionCompletionHandler((status == AVAuthorizationStatus.Authorized),
                                               userDialogResult,
                                               systemDialogResult);
                _avPermissionCompletionHandler = null;
            }
        }
Esempio n. 15
0
        public void MakeSnapshot(string path, int size, Action <bool> callback)
        {
            AVAuthorizationStatus status = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);

            switch (status)
            {
            case AVAuthorizationStatus.NotDetermined:
                AVCaptureDevice.RequestAccessForMediaType(AVMediaType.Video, granded =>
                {
                    if (granded)
                    {
                        Context.MainController.InvokeOnMainThread(() => Write(path, size, callback));
                    }
                });
                break;

            case AVAuthorizationStatus.Restricted:
            case AVAuthorizationStatus.Denied:
                using (var alert = new UIAlertView(D.WARNING, D.CAMERA_NOT_ALLOWED, null, D.OK))
                    alert.Show();
                break;

            case AVAuthorizationStatus.Authorized:
                Write(path, size, callback);
                break;
            }
        }
        /// <summary>
        /// Opens a camera capture view controller.
        /// </summary>
        /// <param name="parent">The parent view controller that invoked the method.</param>
        /// <param name="callback">Action to call after photo is captured.</param>
        /// <param name="onCancel">Action to call if canceling from camera.</param>
        /// <param name="cameraToUse">Can set to default the front or rear camera.</param>
        public static void TakePicture <TViewModel>(BaseViewController <TViewModel> parent, Action <NSDictionary> callback, Action onCancel, UIImagePickerControllerCameraDevice cameraToUse = UIImagePickerControllerCameraDevice.Front)
            where TViewModel : BaseViewModel
        {
            var status = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);

            if (status == AVAuthorizationStatus.NotDetermined)
            {
                AVCaptureDevice.RequestAccessForMediaType(AVMediaType.Video, (accessGranted) =>
                {
                    if (accessGranted)
                    {
                        // Open the camera
                        parent.InvokeOnMainThread(delegate
                        {
                            InitializeCamera(parent, callback, onCancel, cameraToUse);
                        });
                    }
                    // If they have said no do nothing.
                });
            }
            else if (status == AVAuthorizationStatus.Authorized)
            {
                // Open the camera
                InitializeCamera(parent, callback, onCancel, cameraToUse);
            }
            else
            {
                // They said no in the past, so show them an alert to direct them to the app's settings.
                OpenSettingsAlert(parent, "Camera Access Required", "Authorization to access the camera is required to use this feature of the app.");
            }
        }
Esempio n. 17
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();


            // Disable UI. The UI is enabled if and only if the session starts running.

            // Add the open barcode gesture recognizer to the region of interest view.

            // Set up the video preview view.
            this.PreviewView.Session = session;

            // Check video authorization status. Video access is required and audio
            // access is optional. If audio access is denied, audio is not recorded
            // during movie recording.
            switch (AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video))
            {
            case AVAuthorizationStatus.Authorized:
                // The user has previously granted access to the camera.
                break;

            case AVAuthorizationStatus.NotDetermined:
                // The user has not yet been presented with the option to grant
                // video access. We suspend the session queue to delay session
                // setup until the access request has completed.
                this.sessionQueue.Suspend();
                AVCaptureDevice.RequestAccessForMediaType(AVMediaType.Video, (granted) =>
                {
                    if (!granted)
                    {
                        this.setupResult = SessionSetupResult.NotAuthorized;
                    }

                    this.sessionQueue.Resume();
                });
                break;

            default:
                // The user has previously denied access.
                this.setupResult = SessionSetupResult.NotAuthorized;
                break;
            }

            // Setup the capture session.
            // In general it is not safe to mutate an AVCaptureSession or any of its
            // inputs, outputs, or connections from multiple threads at the same time.
            //
            // Why not do all of this on the main queue?
            // Because AVCaptureSession.StartRunning() is a blocking call which can
            // take a long time. We dispatch session setup to the sessionQueue so
            // that the main queue isn't blocked, which keeps the UI responsive.
            this.sessionQueue.DispatchAsync(this.ConfigureSession);

            UISlider focusSlider = new UISlider(new CGRect(60, this.View.Frame.Location.Y - 60, 200, 20));

            // focusSlider.AddTarget(focusSlider, new ObjCRuntime.Selector(AdjustFocusAction), UIControlEvent.ValueChanged);
            focusSlider.MaxValue = 1;
            focusSlider.MinValue = 0;
            this.View.AddSubview(focusSlider);
        }
        protected override void OnElementChanged(ElementChangedEventArgs <CustomCamera> e)
        {
            if (Control == null)
            {
                AVAuthorizationStatus status = AVCaptureDevice.GetAuthorizationStatus(AVAuthorizationMediaType.Video);
                if (status == AVAuthorizationStatus.Authorized)
                { // プライバシー設定でカメラ使用が許可されている
                }
                else if (status == AVAuthorizationStatus.Denied)
                { //  不許可になっている
                }
                else if (status == AVAuthorizationStatus.Restricted)
                { // 制限されている
                }
                else if (status == AVAuthorizationStatus.NotDetermined)
                { // アプリで初めてカメラ機能を使用する場合
                    AVCaptureDevice.RequestAccessForMediaTypeAsync(AVAuthorizationMediaType.Video);
                }
                m_uiCameraPreview = new UICameraPreview(e.NewElement);
                SetNativeControl(m_uiCameraPreview);

                if (e.OldElement != null)
                {
                }
                if (e.NewElement != null)
                {
                }
            }
        }
Esempio n. 19
0
        private static AuthorizationState PlatformGetState(AuthorizationType category)
        {
            EnsureDeclared(category);

            AuthorizationState state;

            switch (category)
            {
            case AuthorizationType.Camera:
                state = AVCaptureDevice.GetAuthorizationStatus(AVAuthorizationMediaType.Video).ToShared();
                break;

            case AuthorizationType.LocationWhenUse:
                state = CLLocationManager.Status.ToShared(false);
                break;

            case AuthorizationType.LocationAlways:
                state = CLLocationManager.Status.ToShared(true);
                break;

            case AuthorizationType.PhotoLibrary:
                state = PHPhotoLibrary.AuthorizationStatus.ToShared();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(category));
            }

            return(state);
        }
        public void RefcountTest()
        {
            TestRuntime.AssertSystemVersion(PlatformName.iOS, 7, 0, throwIfOtherPlatform: false);

            // Bug #27205

            var auth = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);

            switch (auth)
            {
            case AVAuthorizationStatus.Restricted:
            case AVAuthorizationStatus.Denied:
            case AVAuthorizationStatus.NotDetermined:
                Assert.Inconclusive("This test requires video recording permissions.");
                return;
            }

            using (var captureSession = new AVCaptureSession()) {
                using (var videoDevice = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Video)) {
                    foreach (var format in videoDevice.Formats)
                    {
                        for (int i = 0; i < 10; i++)
                        {
                            using (var f = format.FormatDescription) {
                            }
                        }
                    }
                }
            }
        }
Esempio n. 21
0
        private void CheckVideoPermissionAndStart()
        {
            AVFoundation.AVAuthorizationStatus authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);
            switch (authorizationStatus)
            {
            case AVAuthorizationStatus.NotDetermined:
                AVCaptureDevice.RequestAccessForMediaType(AVMediaType.Video, delegate(bool granted)
                {
                    if (granted)
                    {
                        SetupCaptureSession();
                    }
                    else
                    {
                        RenderImageMessage("Please grant Video Capture permission");
                    }
                });
                break;

            case AVAuthorizationStatus.Authorized:
                SetupCaptureSession();
                break;

            case AVAuthorizationStatus.Denied:
            case AVAuthorizationStatus.Restricted:
                RenderImageMessage("Please grant Video Capture permission");
                break;

            default:

                break;
                //do nothing
            }
        }
Esempio n. 22
0
        void CheckCameraPermission()
        {
            string message;
            var    status = AVCaptureDevice.GetAuthorizationStatus(AVAuthorizationMediaType.Video);

            switch (status)
            {
            case AVAuthorizationStatus.NotDetermined:
                message = "Let's take a photo to be tested by the MLKit API!";
                AppDelegate.ShowMessage("Camera Access", message, NavigationController, "Let's do this!", AskForCameraPermission);
                break;

            case AVAuthorizationStatus.Restricted:
            case AVAuthorizationStatus.Denied:
                message = "Open App Settings and grant for camera access to take a photo and test the MLKit API";
                AppDelegate.ShowMessage("Camera Access Denied", message, NavigationController, "Open App Settings", OpenAppSettings);
                break;

            case AVAuthorizationStatus.Authorized:
                OpenCamera();
                break;

            default:
                break;
            }
        }
 private async void AuthorizeCameraUse()
 {
     var authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);
     if (authorizationStatus != AVAuthorizationStatus.Authorized)
     {
         await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video);
     }
 }
 void AbrirCamara()
 {
     if (!UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.Camera))
     {
         ShowMessage("Error", "Camera no disponible", NavigationController);
         return;
     }
     CheckCameraAtuhorizationStatus(AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video));
 }
Esempio n. 25
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            //systemSoundBeep = new SystemSound(NSUrl.FromFilename("Sounds/beep07.mp3"));
            //systemSoundCaution = new SystemSound(NSUrl.FromFilename("Sounds/beep06.mp3"));

            //audioPlayer = AVAudioPlayer.FromUrl(NSUrl.FromFilename("Sounds/beep07.mp3"));
            //audioCautionPlayer = AVAudioPlayer.FromUrl(NSUrl.FromFilename("Sounds/beep06.mp3"));

            // Perform any additional setup after loading the view, typically from a nib.
            this.PreviewView.AddGestureRecognizer(this.OpenBarcodeURLGestureRecognizer);

            // Set up the video preview view.
            this.PreviewView.Session = session;

            // Check video authorization status. Video access is required and audio
            // access is optional. If audio access is denied, audio is not recorded
            // during movie recording.
            switch (AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video))
            {
            case AVAuthorizationStatus.Authorized:
                // The user has previously granted access to the camera.
                break;

            case AVAuthorizationStatus.NotDetermined:
                // The user has not yet been presented with the option to grant
                // video access. We suspend the session queue to delay session
                // setup until the access request has completed.
                this.sessionQueue.Suspend();
                AVCaptureDevice.RequestAccessForMediaType(AVMediaType.Video, (granted) =>
                {
                    if (!granted)
                    {
                        this.setupResult = SessionSetupResult.NotAuthorized;
                    }

                    this.sessionQueue.Resume();
                });
                break;

            default:
                // The user has previously denied access.
                this.setupResult = SessionSetupResult.NotAuthorized;
                break;
            }

            // Setup the capture session.
            // In general it is not safe to mutate an AVCaptureSession or any of its
            // inputs, outputs, or connections from multiple threads at the same time.
            //
            // Why not do all of this on the main queue?
            // Because AVCaptureSession.StartRunning() is a blocking call which can
            // take a long time. We dispatch session setup to the sessionQueue so
            // that the main queue isn't blocked, which keeps the UI responsive.
            this.sessionQueue.DispatchAsync(this.ConfigureSession);
        }
Esempio n. 26
0
        async Task autorizacionCamara()
        {
            var estatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);

            if (estatus != AVAuthorizationStatus.Authorized)
            {
                await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video);
            }
        }
Esempio n. 27
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Disable UI. The UI is enabled if and only if the session starts running.
            this.MetadataObjectTypesButton.Enabled = false;
            this.SessionPresetsButton.Enabled      = false;
            this.CameraButton.Enabled = false;
            this.ZoomSlider.Enabled   = false;

            // Add the open barcode gesture recognizer to the region of interest view.
            this.PreviewView.AddGestureRecognizer(this.OpenBarcodeURLGestureRecognizer);

            // Set up the video preview view.
            this.PreviewView.Session = session;

            // Check video authorization status. Video access is required and audio
            // access is optional. If audio access is denied, audio is not recorded
            // during movie recording.
            switch (AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video))
            {
            case AVAuthorizationStatus.Authorized:
                // The user has previously granted access to the camera.
                break;

            case AVAuthorizationStatus.NotDetermined:
                // The user has not yet been presented with the option to grant
                // video access. We suspend the session queue to delay session
                // setup until the access request has completed.
                this.sessionQueue.Suspend();
                AVCaptureDevice.RequestAccessForMediaType(AVMediaType.Video, (granted) =>
                {
                    if (!granted)
                    {
                        this.setupResult = SessionSetupResult.NotAuthorized;
                    }

                    this.sessionQueue.Resume();
                });
                break;

            default:
                // The user has previously denied access.
                this.setupResult = SessionSetupResult.NotAuthorized;
                break;
            }

            // Setup the capture session.
            // In general it is not safe to mutate an AVCaptureSession or any of its
            // inputs, outputs, or connections from multiple threads at the same time.
            //
            // Why not do all of this on the main queue?
            // Because AVCaptureSession.StartRunning() is a blocking call which can
            // take a long time. We dispatch session setup to the sessionQueue so
            // that the main queue isn't blocked, which keeps the UI responsive.
            this.sessionQueue.DispatchAsync(this.ConfigureSession);
        }
Esempio n. 28
0
 void TryOpenCamera()
 {
     if (!UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.Camera))
     {
         AVAuthorizationStatus authStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);
         CheckCamaraAutorizationStatus(authStatus);
         return;
     }
 }
Esempio n. 29
0
 void OpenCamera()
 {
     if (!UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.Camera))
     {
         //TODO: Print a message
         ShowMessage("Error", "Camera resource is not available", NavigationController);
         return;
     }
     CheckCameraAtuhorizationStatus(AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video));
 }
Esempio n. 30
0
        async Task <bool> AuthorizeCameraUse()
        {
            var authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);

            if (authorizationStatus != AVAuthorizationStatus.Authorized)
            {
                return(await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video));
            }
            return(true);
        }