c++ - iOS Vuforia error after entering from background


Keywords:c++ 


Question: 

I use Vuforia SDK, version 6.2.9 in my iOS App. All work's fine, but there is an error when the app enter from background.

The viewcontroller running VUFORIA is listening for UIApplicationWillResignActiveNotification and UIApplicationDidBecomeActiveNotification notifications. In the case of UIApplicationWillResignActiveNotification pause AR, in the case of UIApplicationDidBecomeActiveNotification resume AR.

// we use the iOS notification to pause/resume the AR when the application goes (or come back from) background

[[NSNotificationCenter defaultCenter]
 addObserver:self
 selector:@selector(pauseAR)
 name:UIApplicationWillResignActiveNotification
 object:nil];

[[NSNotificationCenter defaultCenter]
 addObserver:self
 selector:@selector(resumeAR)
 name:UIApplicationDidBecomeActiveNotification
 object:nil];

These are the methods

- (void) pauseAR {
   NSError * error = nil;
   if (![vapp pauseAR:&error]) {
      NSLog(@"Error pausing AR:%@", [error description]);
   }
}

- (void) resumeAR {

    NSError * error = nil;
    if(! [vapp resumeAR:&error]) {
        NSLog(@"Error resuming AR:%@", [error description]);
    }

    // on resume, we reset the flash
    Vuforia::CameraDevice::getInstance().setFlashTorchMode(false);

    [self handleRotation:self.interfaceOrientation];
}

When I return to the scan mode, after the app has entered from background, the camera is frozen, with error Could not find a UIView with CAEAGLLayer or CAMetalLayer layer class that responds to selector renderFrameVuforia

2017-07-17 11:13:01.187406+0200 App[8689:2961061] frame: {{0, 0}, {375, 667}}
2017-07-17 11:13:01.243707+0200 App[8689:2961061] DEBUG/AR(8689) Could not find a UIView with CAEAGLLayer or CAMetalLayer layer class that responds to selector renderFrameVuforia
2017-07-17 11:13:01.253958+0200 App[8689:2961061] Vuforia Library version 6.2.9
2017-07-17 11:13:01.731099+0200 App[8689:2961061] AR View: Rotating to Portrait
2017-07-17 11:13:01.731406+0200 App[8689:2961061] frame: {{0, 0}, {375, 667}}
2017-07-17 11:13:01.731562+0200 App[8689:2961061] VideoBackgroundConfig: size: 750,1334
2017-07-17 11:13:01.731589+0200 App[8689:2961061] VideoMode:w=1280 h=720
2017-07-17 11:13:01.731611+0200 App[8689:2961061] width=750.000 height=1334.000
2017-07-17 11:13:01.731638+0200 App[8689:2961061] ViewPort: X,Y: 0,0 Size X,Y:750,1334
2017-07-17 11:13:02.598959+0200 App[8689:2962160] INFO/AR(8689) 2017-07-18 11:13:02: Completed CloudReco transaction with ID '6f5c61ecc07741a7b652242abf909479'
2017-07-17 11:13:02.843834+0200 App[8689:2961061] frame: {{0, 0}, {375, 667}}
2017-07-17 11:13:02.844215+0200 App[8689:2961061] frame: {{0, 0}, {375, 667}}
2017-07-17 11:13:02.860971+0200 App[8689:2961061] DEBUG/AR(8689) UIView has CAEAGLLayer layer class
2017-07-17 11:13:02.861114+0200 App[8689:2961061] DEBUG/AR(8689) UIView does not respond to selector renderFrameVuforia
2017-07-17 11:13:02.861191+0200 App[8689:2961061] DEBUG/AR(8689) UIView has CAEAGLLayer layer class
2017-07-17 11:13:02.861222+0200 App[8689:2961061] DEBUG/AR(8689) UIView does not respond to selector renderFrameVuforia

Thanks for your help!


1 Answer: 

In which method you call pauseAR() ?

I faced the same issue when popped back to the ViewController(which own the EAGLView) the camera is frozen.

I call pauseAR() in viewWillDisappear() and resumeAR() in viewWillAppear(), as the issue came out the delegate method renderFrameVuforia() in EAGLView never get called, I think this is problem cause the issue:

Could not find a UIView with CAEAGLLayer or CAMetalLayer layer class that responds to selector renderFrameVuforia

So I looked up the Vuforia Developer Library and found:

The app's view hierarchy is set up completely before calling QCAR::onResume() (at which point QCAR attempts to locate the app's view conforming to UIGLViewProtocol).

I changed resumeAR() method called position to viewDidAppear(), everything work as usual. Hope this can help you.