Start a new topic

Handling no access to camera

Handling no access to camera


Ha, I knew I'd figure it out as soon as I posted this. Since I was initializing the WTArchitectView within an InvokeOnMainThread statement the Start() method was never called. Add this to my InvokeOnMainThread action resolved the issue.

Hello,

I'm using the Xamarin bindings in my iOS project but I don't think my problem is releated to the binding. I'm trying to handle behavior when a user does not allow access to the camera. I'm hoping to hook into a delegate that'll allow me to navigate the user to another scene in my storyboard if they do not allow access to the camera.

I'm tried implementing a WTArchitectViewDelegate and overriding some events but none of them seem to fire when access is denied by the user. This is the code that I'm using to instantiate my WTArchitectView:

if (WTArchitectView.IsDeviceSupportedForAugmentedRealityMode (WTAugmentedRealityMode._IR)) {

arView = new WTArchitectView (UIScreen.MainScreen.Bounds, null, WTAugmentedRealityMode._IR);

arView.SetLicenseKey ("key removed");

 

var absoluteWorldUrl = NSBundle.MainBundle.BundleUrl.AbsoluteString + "PosterTarget/index.html";

var u = new NSUrl (absoluteWorldUrl);

arView.LoadArchitectWorldFromUrl (u);

 

_arViewDelegate = new BackToXamarinViewDelegate (this);

arView.Delegate = _arViewDelegate;

 

this.View.AddSubview (arView);

this.View.SendSubviewToBack (arView);

}

 

I then went down the route of trying to request the camera permission before Wikitude and then handle accordingly. However, attempting to initialize the WTArchitectView does not seem to work inside of an InvokeOnMainThread call:

 

var captureDevices = AVCaptureDevice.DevicesWithMediaType (AVMediaType.Video);

var hasBackCamera = (captureDevices.ToList ().Find (d => d.Position == AVCaptureDevicePosition.Back) != null);

 

if (hasBackCamera) {

AVCaptureDevice.RequestAccessForMediaType (AVMediaType.Video, (bool isCameraAccessGranted) => {

 

if (WTArchitectView.IsDeviceSupportedForAugmentedRealityMode (WTAugmentedRealityMode._IR)) {

 

if (isCameraAccessGranted) {

InvokeOnMainThread (() => {

arView = new WTArchitectView (UIScreen.MainScreen.Bounds, null, WTAugmentedRealityMode._IR);

arView.SetLicenseKey ("key removed");

 

var absoluteWorldUrl = NSBundle.MainBundle.BundleUrl.AbsoluteString + "PosterTarget/index.html";

var u = new NSUrl (absoluteWorldUrl);

arView.LoadArchitectWorldFromUrl (u);

 

_arViewDelegate = new BackToXamarinViewDelegate (this);

arView.Delegate = _arViewDelegate;

 

this.View.AddSubview (arView);

this.View.SendSubviewToBack (arView);

});

} else {

// permission was not given to the camera

InvokeOnMainThread (() => {

this.PerformSegue ("NoCameraPermission", this);

});

... rest of code omitted since it doesn't really apply ...

 

How are people handling this situation? I can't find anything in the documentation and can't see anything in the forums about this. Any ideas?

 

Thanks!
Login or Signup to post a comment