protected async override void RequestAccess() { await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video); // But the continuation is on a background thread, so use InvokeOnMainThread to update the UI UpdateStatus(); }
async private void CheckCamaraAutorizationStatus(AVAuthorizationStatus authorizationStatus) { switch (authorizationStatus) { case AVAuthorizationStatus.NotDetermined: await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video); CheckCamaraAutorizationStatus(authorizationStatus); break; case AVAuthorizationStatus.Restricted: InvokeOnMainThread(() => ShowMessage("Acceso a Camara Restringido", "Por que no muestras los packs??? Te quieres morir??", NavigationController)); break; case AVAuthorizationStatus.Denied: InvokeOnMainThread(() => ShowMessage("Acceso a Camara Denegado", "Por que no muestras los packs??? Te quieres morir??", NavigationController)); break; case AVAuthorizationStatus.Authorized: InvokeOnMainThread(() => { var imagePickerController = new UIImagePickerController { SourceType = UIImagePickerControllerSourceType.Camera, Delegate = this }; PresentViewController(imagePickerController, true, null); }); break; default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Suspends the session and requests permission for video. /// </summary> private void RequestPermission() { this.sessionQueue.Suspend(); AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video); CheckPermission(false); this.sessionQueue.Resume(); }
/// <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); }
void CheckCameraAtuhorizationStatus(AVAuthorizationStatus authorizationStatus) { switch (authorizationStatus) { case AVAuthorizationStatus.NotDetermined: AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video); break; case AVAuthorizationStatus.Restricted: InvokeOnMainThread(() => ShowMessage("Fail", "Acceso Restringido", NavigationController)); break; case AVAuthorizationStatus.Denied: InvokeOnMainThread(() => ShowMessage("Fail", "Acceso Denegado", NavigationController)); break; case AVAuthorizationStatus.Authorized: InvokeOnMainThread(() => { var Camera = new UIImagePickerController { SourceType = UIImagePickerControllerSourceType.Camera, Delegate = this }; PresentViewController(Camera, true, null); }); break; default: throw new ArgumentOutOfRangeException(); } }
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; } }
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) { } } }
/// <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()); }
private async void AuthorizeCameraUse() { var authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video); if (authorizationStatus != AVAuthorizationStatus.Authorized) { await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video); } }
async Task autorizacionCamara() { var estatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video); if (estatus != AVAuthorizationStatus.Authorized) { await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video); } }
async Task AuthorizeVideoInputUse() { var authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video); if (authorizationStatus != AVAuthorizationStatus.Authorized) { await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video); } VideoInputPermissionGranted = true; }
//This method is synchronous... protected void RequestCameraAccess() { //But inside, use an async lambda to request permission... Task.Run(async() => { var _ = await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video); //...But the continuation is on a background thread, so use InvokeOnMainThread to update the UI UpdateStatus(); }); }
public static async Task <bool> AuthorizeMic() { var authStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Audio); if (authStatus != AVAuthorizationStatus.Authorized) { return(await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Audio)); } return(true); }
async Task <bool> AuthorizeCameraUse() { var authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video); if (authorizationStatus != AVAuthorizationStatus.Authorized) { return(await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video)); } return(true); }
// //Camera access Authozation //* async Task CameraAuterization() { AVAuthorizationStatus acvStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video); if ( acvStatus != AVAuthorizationStatus.Authorized ) { await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video); } }//*/
//async partial void TakePhotoButtonTapped() { } public async Task AuthorizeCameraUse() { Debug.WriteLine("CameraService:AuthorizeCameraUse"); var authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video); if (authorizationStatus != AVAuthorizationStatus.Authorized) { await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video); } Debug.WriteLine("CameraService:AuthorizeCameraUse"); return; }
public async Task AuthorizeCameraUse() { var authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video); if (authorizationStatus != AVAuthorizationStatus.Authorized) { await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video); } else { await Task.Delay(1000); } }
public async Task <bool> GetCameraPermissions() { var authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video); if (authorizationStatus != AVAuthorizationStatus.Authorized) { bool success = await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video); return(success); } return(true); }
public async override void ViewDidLoad() { base.ViewDidLoad(); var licensePath = Path.Combine(NSBundle.MainBundle.BundlePath, "License/AbbyyRtrSdk.license"); engine = RTREngine.SharedEngineWithLicenseData(NSData.FromFile(licensePath)); if (engine == null) { throw new InvalidOperationException("tmp"); } textCaptureServiceDelegate = new TextCaptureServiceDelegate(this); textCaptureService = engine.CreateTextCaptureServiceWithDelegate(textCaptureServiceDelegate); NSSet selectedRecognitionLanguages = new NSSet("English"); textCaptureService.SetRecognitionLanguages(selectedRecognitionLanguages); //self.languagesTableView.register(UITableViewCell.self, forCellReuseIdentifier: RTRVideoScreenCellName) //self.languagesTableView.tableFooterView = UIView(frame: CGRect.zero) languagesTableView.Hidden = true; captureButton.Selected = false; captureButton.SetTitle("Stop", UIControlState.Selected); captureButton.SetTitle("Start", UIControlState.Normal); //let recognizeLanguageButtonTitle = self.languagesButtonTitle() //self.recognizeLanguageButton.title = recognizeLanguageButtonTitle var status = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video); switch (status) { case AVAuthorizationStatus.Authorized: ConfigureCompletionAccess(true); break; case AVAuthorizationStatus.NotDetermined: var granted = await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video); ConfigureCompletionAccess(granted); break; case AVAuthorizationStatus.Restricted: case AVAuthorizationStatus.Denied: ConfigureCompletionAccess(false); break; } }
private async Task ValidateCameraAccess() { if (!IsUsageKeyDefined("NSCameraUsageDescription")) { throw new InvalidOperationException("Info.plist must define NSCameraUsageDescription"); } var isAllowed = await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaTypes.Video.GetConstant()); if (!isAllowed) { throw new UnauthorizedAccessException(); } }
private async void AuthorizeCameraUse() { var authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video); if (authorizationStatus != AVAuthorizationStatus.Authorized) { if (!await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video)) { _isCameraAccessDenied = true; return; } } SetupLiveCameraStream(); }
internal static async Task <PermissionStatus> RequestAVPermissionStatusAsync(NSString mediaType) { try { var auth = await AVCaptureDevice.RequestAccessForMediaTypeAsync(mediaType); return(auth ? PermissionStatus.Granted : PermissionStatus.Denied); } catch (Exception ex) { Debug.WriteLine($"Unable to get {mediaType} permission: " + ex); return(PermissionStatus.Unknown); } }
public async void AuthorizeCameraUse() { try { var authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video); if (authorizationStatus != AVAuthorizationStatus.Authorized) { await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video).ConfigureAwait(true); } } catch (Exception) { } }
async System.Threading.Tasks.Task AuthorizeMediaUse() { var authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video); if (authorizationStatus != AVAuthorizationStatus.Authorized) { await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video); } authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Audio); if (authorizationStatus != AVAuthorizationStatus.Authorized) { await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Audio); } }
private async Task AuthorizeCameraUse() { try { var authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video); if (authorizationStatus != AVAuthorizationStatus.Authorized) { await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video); } } catch (Exception ex) { Debug.WriteLine(ex.StackTrace); } }
async Task <bool> AuthorizeCameraUse() { var authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video); // Ask for Camera permissions, if not already authorized if (authorizationStatus != AVAuthorizationStatus.Authorized) { var access = await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video); // Refresh authorization status authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video); return(authorizationStatus == AVAuthorizationStatus.Authorized); } return(true); }
public async Task <bool> RequestCameraAccess() { var status = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video); if (status == AVAuthorizationStatus.Authorized) { return(true); } else if (status == AVAuthorizationStatus.NotDetermined) { return(await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video)); } else { return(false); } }
public async void CameraMedia() { var authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video); if (authorizationStatus != AVAuthorizationStatus.Authorized) { var access = await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video); if (access) { GotAccessToCamera(); } } else { GotAccessToCamera(); } }
private async void AuthorizeCameraUse() { var authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video); if (authorizationStatus != AVAuthorizationStatus.Authorized) { if (!await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video)) { enableCameraAccess.Hidden = false; photoButton.Hidden = true; flashButton.Hidden = true; swapCameraButton.Hidden = true; return; } } SetupLiveCameraStream(); }
async void ExpenseDetail_RecieptBtn_TouchUpInside(object sender, EventArgs e) { _isFromCamara = true; CoreUtilities.GetLogService().Log(nameof(ExpenseDetailController), "adding receipt"); var authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video); CoreUtilities.GetLogService().Log(nameof(ExpenseDetailController), "checking for camera authorization"); if (authorizationStatus != AVAuthorizationStatus.Authorized) { CoreUtilities.GetLogService().Log(nameof(ExpenseDetailController), "asking for camera access"); await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video); } CoreUtilities.GetLogService().Log(nameof(ExpenseDetailController), "loading camera"); Camera.TakePicture(this, (obj) => { var photo = obj.ValueForKey(new NSString("UIImagePickerControllerOriginalImage")) as UIImage; _recieptImageData = photo.AsJPEG(); }); }