Start a new topic
Solved

NSInternalInconsistencyException when i allow camera usage

Hi,

i'm developing with Xamarin, SDK Wikitude 8.9.1 and i'm working with the JS API. I realized that when I start the application on my iPhone X for the first time, when I allow the use of the camera, the following error is generated:

Foundation.MonoTouchException has been thrown
Objective-C exception thrown.  Name: NSInternalInconsistencyException Reason: Invalid parameter not satisfying: context
Native stack trace:
	0   CoreFoundation                      0x0000000195bf1820 FF63481D-FB6A-353B-B2C1-AC4EAECF594D + 1226784
	1   libobjc.A.dylib                     0x0000000195919fa4 objc_exception_throw + 56
	2   CoreFoundation                      0x0000000195af3c4c FF63481D-FB6A-353B-B2C1-AC4EAECF594D + 187468
	3   Foundation                          0x0000000195f296f4 3C682044-3249-3938-8111-F2F12D066D2B + 554740
	4   WikitudeSDK                         0x0000000102e159b0 -[WTVideoCameraSystemOpenGLESConnector eaglContextForVideoCameraSystem:] + 240
	5   WikitudeSDK                         0x0000000102e48310 -[WTVideoCameraSystemOpenGLES videoCameraWillStartCapturing:] + 76
	6   WikitudeSDK                         0x0000000102e3f040 __32-[WTVideoCamera startCapturing:]_block_invoke + 68
	7   libdispatch.dylib                   0x00000001958bf184 B7EED4C7-560D-3DA6-9B50-ED52A150AAC6 + 377220
	8   libdispatch.dylib                   0x00000001958a2dc8 B7EED4C7-560D-3DA6-9B50-ED52A150AAC6 + 261576
	9   WikitudeSDK                         0x0000000102e3efe8 -[WTVideoCamera startCapturing:] + 124
	10  WikitudeSDK                         0x0000000102e049a4 _ZN8wikitude5apple4impl25AppleCameraModuleInternal5startENSt3__18functionIFvbEEE + 176
	11  WikitudeSDK                         0x0000000102e1be78 _ZNSt3__110__function6__funcIZZN8wikitude3ios4impl15iOSCameraModule7doStartENS_8functionIFvbEEEENK3$_1clEvEUlPNS4_9iOSCameraEE_NS_9allocatorISC_EEFvSB_EEclEOSB_ + 248
	12  WikitudeSDK                         0x0000000102e234dc _ZNSt3__110__function6__funcIZN8wikitude3ios4impl23iOSCameraModuleInternal33findCameraMatchingCharacteristicsENS2_3sdk4impl14CameraPositionENS7_16CameraResolutionENS7_15CameraFrameRateENS7_25CameraResolutionMatchModeENS_8functionIFvPNS4_9iOSCameraEEEENSC_IFvRNS7_5ErrorEEEEE3$_3NS_9allocatorISL_EEFiNS_13unordered_setISE_NS_4hashISE_EENS_8equal_toISE_EENSM_ISE_EEEEEEclEOSU_ + 564
	13  WikitudeSDK                         0x0000000102e21d70 _ZN8wikitude3ios4impl23iOSCameraModuleInternal19getAvailableCamerasENSt3__18functionIFiNS3_13unordered_setIPNS1_9iOSCameraENS3_4hashIS7_EENS3_8equal_toIS7_EENS3_9allocatorIS7_EEEEEEENS4_IFvRNS_3sdk4impl5ErrorEEEE + 2944
	14  WikitudeSDK                         0x0000000102e21130 _ZN8wikitude3ios4impl23iOSCameraModuleInternal33findCameraMatchingCharacteristicsENS_3sdk4impl14CameraPositionENS4_16CameraResolutionENS4_15CameraFrameRateENS4_25CameraResolutionMatchModeENSt3__18functionIFvPNS1_9iOSCameraEEEENSA_IFvRNS4_5ErrorEEEE + 132
	15  WikitudeSDK                         0x0000000102e1ac58 _ZN8wikitude3ios4impl15iOSCameraModule33findCameraMatchingCharacteristicsENS_3sdk4impl14CameraPositionENS4_16CameraResolutionENS4_15CameraFrameRateENS4_25CameraResolutionMatchModeENSt3__18functionIFvPNS1_9iOSCameraEEEENSA_IFvRNS4_5ErrorEEEE 

  

image


I think the error is in "ViewController.cs" but I don't understand what I'm doing wrong. 


 This is the code in "ViewController.cs":

using System;
using Foundation;
using UIKit;
using CoreGraphics;
using AVFoundation;
using WikitudeComponent.iOS;
using Adeon.iOS.CoreServices;



namespace Adeon.iOS
{
    public partial class ViewController : UIViewController, IUIGestureRecognizerDelegate
    {
        protected class ArchitectDelegate : WTArchitectViewDelegate
        {
            [Weak]
            protected ViewController arExperienceViewController;

            public ArchitectDelegate(ViewController arExperienceViewController)
            {
                this.arExperienceViewController = arExperienceViewController;
            }

            public override void DidFinishLoadNavigation(WTArchitectView architectView, WTNavigation navigation)
            {
                Console.WriteLine("Finished loading Architect World");
                arExperienceViewController.ArchitectWorldFinishedLoading(navigation);
            }

            public override void DidFailToLoadNavigation(WTArchitectView architectView, WTNavigation navigation, NSError error)
            {
                string errorMessage = error.LocalizedDescription + " ('" + navigation.OriginalURL + "')";
                UIAlertController failedToLoadArchitectWorldAlertController = UIAlertController.Create("Failed to load Architect World", errorMessage, UIAlertControllerStyle.Alert);
                failedToLoadArchitectWorldAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));

                arExperienceViewController.PresentViewController(failedToLoadArchitectWorldAlertController, true, null);
            }

            public override UIViewController PresentingViewControllerForViewControllerPresentationInArchitectView(WTArchitectView architectView)
            {
                return arExperienceViewController;
            }
        }

        public ViewController(IntPtr handle) : base(handle)
        {

        }

        protected class NavigationControllerDelegate : UINavigationControllerDelegate
        {
            [Weak]
            protected WTArchitectView architectView;

            public NavigationControllerDelegate(WTArchitectView architectView)
            {
                this.architectView = architectView;
            }

        }

        protected WTArchitectView architectView;
        protected ArchitectDelegate delegateObject;

        [Weak]
        protected WTNavigation loadedArExperienceNavigation;
        protected WTNavigation loadingArExperienceNavigation;

        protected NSObject applicationWillResignActiveObserver;
        protected NSObject applicationDidBecomeActiveObserver;

        private WTAuthorizationRequestManager authorizationRequestManager = new WTAuthorizationRequestManager();

        protected bool isRunning;

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            architectView = new WTArchitectView();
            architectView.SetLicenseKey("rXxGPSn4WA2Bkg6vd1j176qXR6Y9iKULHtta8L2EFDvj8NZymFAkUWOlC8fgj6oUE59u7DLgXTAqU1we2tmkQ2drwhcaxx/FxxJacaM0462FMqDElT7a6klWFLSaf/7B20kiUmiHcriRWTS4lX3l+xN6+X/rwV+DIL+OXZsEf9hTYWx0ZWRfX0/WkNROVvDYiF7eGx0lP/XutcXlZX2otUyKY1s/Q1AxtFtrHRvEeUw11Ti+2O/qij12LF/cOdPMEL2/bKe0bbFHCVJR/lpQEvxG7o25We3l58t1ZPsDzOziNvxD4g8e5HHCILFwFXzesbOMLhc+LrdulPh6sUsrmGiJOmln7dPyHMgxWRa8rYuUR19hRihOftJ1593Pkz1j324PDUoNKYWeHt2gYzc4z3Prdy/oCO3g5hBdrFLnsRdWzfdjyVNR34b+iaCcnUckSMCQ2k7RohreNh5JEDK5DMHCD7dbUc//SS7qFbjmd8V/rworMeA4X/VuZPaJrufYUzXHZJV2xp3zjrF0qj/dO+E2mBA1kJwnZ0LE4XmDwAElabT0U3K4E2lM4UR+I3r3SNj3/6K4SVKs+wtbk5ie8TkYbfXhkWQKeug8Bn1lOsPVKGUuAxRtCni4L2HQpQ2vtbDZgdVaEAMRjPRoEmx0txT3W1FNJhkJCTUL05jM/sEn3VcCEzUxKA+snBjk9ys+D497kw/FL/qW81bHWPi6gNev8LNLxzgdvrcoCBepMko5HrGq0UyJNOg8Xz+Zyl0VtC2X/qIu+iVfd54/E2vr5A==");
            delegateObject = new ArchitectDelegate(this);
            architectView.Delegate = delegateObject;
            architectView.TranslatesAutoresizingMaskIntoConstraints = false;
            Add(architectView);

            architectView.CenterXAnchor.ConstraintEqualTo(View.CenterXAnchor).Active = true;
            architectView.CenterYAnchor.ConstraintEqualTo(View.CenterYAnchor).Active = true;
            architectView.WidthAnchor.ConstraintEqualTo(View.WidthAnchor).Active = true;
            architectView.HeightAnchor.ConstraintEqualTo(View.HeightAnchor).Active = true;

            EdgesForExtendedLayout = UIRectEdge.None;
        }

        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            LoadArExperience();
            StartArchitectViewRendering();

            applicationWillResignActiveObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.WillResignActiveNotification, ApplicationWillResignActive);
            applicationDidBecomeActiveObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.DidBecomeActiveNotification, ApplicationDidBecomeActive);
        }


        public override void ViewDidDisappear(bool animated)
        {
            base.ViewDidDisappear(animated);

            StopArchitectViewRendering();

            NSNotificationCenter.DefaultCenter.RemoveObserver(applicationWillResignActiveObserver);
            NSNotificationCenter.DefaultCenter.RemoveObserver(applicationDidBecomeActiveObserver);
        }

        public override void DidReceiveMemoryWarning()
        {
            base.DidReceiveMemoryWarning();
            // Release any cached data, images, etc that aren't in use.
        }

        /* FORSE POSSO CANCELLARLO */
        public override void ViewWillTransitionToSize(CGSize toSize, IUIViewControllerTransitionCoordinator coordinator)
        {
            if (coordinator != null)
            {
                coordinator.AnimateAlongsideTransition((IUIViewControllerTransitionCoordinatorContext context) =>
                {
                    UIInterfaceOrientation newInterfaceOrientation = UIApplication.SharedApplication.StatusBarOrientation;
                    architectView.SetShouldRotateToInterfaceOrientation(true, newInterfaceOrientation);
                }, null);
            }
            else
            {
                UIInterfaceOrientation newInterfaceOrientation = UIApplication.SharedApplication.StatusBarOrientation;
                architectView.SetShouldRotateToInterfaceOrientation(true, newInterfaceOrientation);
            }

            base.ViewWillTransitionToSize(toSize, coordinator);
        }

        public void ArchitectWorldFinishedLoading(WTNavigation navigation)
        {
            if (loadingArExperienceNavigation.Equals(navigation))
            {
                loadedArExperienceNavigation = navigation;
            }
        }

        #region Notifications
        private void ApplicationWillResignActive(NSNotification notification)
        {
            StopArchitectViewRendering();
        }

        private void ApplicationDidBecomeActive(NSNotification notification)
        {
            StartArchitectViewRendering();
        }
        #endregion

        #region Private Methods
        private void LoadArExperience()
        {
            WTFeatures requiredFeatures = WTFeatures.Geo;

            ArExperienceAuthorizationController.AuthorizeRestricedAPIAccess(authorizationRequestManager, requiredFeatures, () => {
                NSUrl fullArExperienceURL = NSBundle.MainBundle.GetUrlForResource("index", "html", "Milan");
                loadingArExperienceNavigation = architectView.LoadArchitectWorldFromURL(fullArExperienceURL);
            }, (UIAlertController alertController) => {
                PresentViewController(alertController, true, null);
            });
        }

        private void StartArchitectViewRendering()
        {
            if (!architectView.IsRunning)
            {
                architectView.Start((WTArchitectStartupConfiguration architectStartupConfiguration) =>
                {
                    architectStartupConfiguration.CaptureDevicePosition = AVCaptureDevicePosition.Back;
                    architectStartupConfiguration.CaptureDeviceResolution = WTCaptureDeviceResolution.WTCaptureDeviceResolution_AUTO;
                    architectStartupConfiguration.CaptureDeviceFocusMode = AVCaptureFocusMode.ContinuousAutoFocus;
                }, (bool success, NSError error) =>
                {
                    isRunning = success;
                });
            }
        }

        private void StopArchitectViewRendering()
        {
            if (isRunning)
            {
                architectView.Stop();
            }
        }
        #endregion
    }
}

 This is the github link of the project: https://github.com/Pische/Adeon.


I have tested with your example application and it does not have this problem.


Many thanks in advance!

Vincenzo


I see that a warning also appears with this message:

 

/Users/"MyUser"/Documents/Development Projects/Visual Studio/Adeon/iOS/ld: Warning: linking against a dylib which is not safe for use in application extensions: /Users/"MyUser"/Documents/Development Projects/Visual Studio/Adeon/iOS/obj/iPhone/Debug/device-builds/iphone10.6-13.2.2/mtouch-cache/WikitudeSDK.framework/WikitudeSDK (Adeon.iOS)

 

Hi Vincenzo,


Thx for providing the details. As you mention that the sample app is working without any issues and that this error is thrown only on the first startup, when you allow the use of the camera, it sounds like an issue with the build setup and the (camera) permission handling. Did you compare the sample app setup with yours and made sure that the settings / handling is done as in the sample app?


Please recheck if the permissions are handled correctly?


Thx and greetings

Nicola

Login or Signup to post a comment