Camera freezes when I come back to viewcontroller containing ARSCNView - ios

I am working on ARKit where I save a video during an ARSession. I present another view controller where I can watch my video. When I come back to my first view controller, the camera seems to be frozen although session delegates are called. I cannot add nodes either.

Related

Camera in a Container view

I am making an app in Xcode 8 using swift 3. Its a tabbed view application. For one of its tab I want a camera interface. so whenever that tab loads I need to show the camera. I want tab bar to stay there permanent, so I took a container view. I am using ImagepickerController and loading the Camera in ViewDidAppear method. so camera loads along with tab click. The problem is I wanted camera in that specific container size. But UIImageviewcontroller is making the interface in a full screen. Is there any way to force it to that container size or custom camera is the only option?
This is not possible using UIImagePickerController. From the documentation:
Present the user interface.
On iPhone or iPod touch, do this modally (full-screen) by calling the present(_:animated:completion:) method of the currently active view controller, passing your configured image picker controller as the new view controller.
I'm afraid you need to read this:
Fully-Customized Media Capture and Browsing
To perform fully-customized image or movie capture, instead use the AV Foundation framework as described in Still and Video Media Capture. Camera access using the AV Foundation framework is available starting in iOS 4.0.
Try to not use ImagepickerController as the tabbarController's item, just use a UIViewController as item, and the ImagepickerController's view added to the UIViewController's view. so that you can controll the contain size by you self.
[self addChildViewController:self.imagepickerController];
[self.view addSubview:self.imagepickerController.view];
//do something like layout the self.imagepickerController.view at here
[self.imagepickerController didMoveToParentViewController:self];

How to pre-load a camera in a PageViewController so that there is no loading animation?

My app uses three view controllers in a Page View Controller. The user swipes left to access a camera. When the user navigates to the camera view, there is a clunky default camera loading animation. I would like the camera to be pre-loaded so that the user sees a fully active camera the moment they swipe left and by doing so eliminate the loading animation.
The app is fully in Swift and the camera uses AVFoundation with a custom camera switcher and a label.
You can use a shared or global variable for the capture session and initiate/start the capture session when your main VC loads. Then when your user swipes yo the other VC the session will already be in memory and you just need to set the frame.

ios keep view in memory

I'm creating an app that plays music and has a nice UI for the album art and progress bar. The problem is when the user leaves the player view and goes back, the player UI has to be reloaded and you see a flash while the progress bar is resized and the album art is loaded.
Is there any way to keep items in memory when you leave a controller? Similar to how you go between playlists and player view on the iPhone music app, there is no lag or delay in seeing the artwork or song progress, it's there from the beginning.
Or am I thinking about this the wrong way?
I am assuming you are going back and forth using a UINavigationController, if so the default behavior is that the view controller will be released when you go back, as the only strong reference to it is in the UINavigationController stack, when it is popped the reference is lost, and therefore your controller is deallocated.
If you want to avoid this, all you need to do is have any other object have a strong reference to your view controller. An easy way to do it would be whenever you initialize your controller, in that class have a strong property that holds a reference to the view controller you do not want to lose.
Hope that helps.

MPMoviePlayerPlaybackDidFinishNotification fires when presenting another view controller

I have created my own MoviePlayerViewController derived from MPMoviePlayerViewController, I present it using the standard presentMoviePlayerViewController method - all works fine. On top of the movie player controller, I present another ShareThisMovie view controller when the user clicks some button (after I pause the movie). I do this using presentViewController.
I don't know why but as soon as the new VC comes up, the underlying MoviePlayerViewController immediately fires MPMoviePlayerPlaybackDidFinishNotification, which I respond to by dismissing the entire VC hierarchy, so the user does not have a chance to interact with the ShareThisMovie controller.
Even if I ignore the notification, still the fact that the movie player fires it means that once the ShareThisMovie controller closes, the movie STARTS OVER FROM THE BEGINNING. This is clearly not what I want...
Why is the MoviePlayerController firing this event? How do I ensure it doesn't, or how to I workaround this? I tried storing the last playback location before showing the ShareThisVideo controller, and setting it back afterwards, but it still plays from the beginning...
tnx
This is happening because when you moving from MoviePlayerViewController to another view controller the MPMoviePlayer stops it playing...so your MPMoviePlayerPlaybackDidFinishNotification Delegate is calling.
you can not continue playing MPMoviePlayer when you are on another ViewController.
one solution is insted of presenting ShareThisMovieviewcontroller, you can simply add UIView for sharing on top of MPMoviePlayer in same controller. this will prevents the MPMoviePlayer to stop.
Not exactly an answer rather than a workaround, but I ended up changing the design: instead of deriving from MPMoviePlayerViewController, I derived from the standard UIViewController, and embedded an MPMoviePlayerController inside it. For some reason, when doing this, the player did not raise a didFinish event when I presented some other VC on top of my player view controller...
Guess my conclusion for now is not to derive a VC from MPMoviePlayerViewController...

Handle loading of content then go to different scenes

I have two scenes from where the user can enter information (one is actually scanning a barcode, the other enter the number manually)
From there, I want to download information from my backend.
Depending on what I get back, I want to go to one or another scene.
Here is a sample of my storyboard:
I don't know how to handle the loading part. My first idea was to have a scene with only a spinner and download the content from here. Once I get it I can choose to which scene I want to go to and it's done. But...
When the user clicks the "Back" button from the scenes on the right, he goes back to the "loading" scene instead of the last "logical" scene (the input scene).
So my question is two-fold:
Do I handle the download correctly, by using a scene just for that?
If I do it right, how do I go back to the last input scene instead of going back to the loading scene? (I found some solutions to unwind the segue, but none that use the navigation controller, which I want to use)
Thanks
Using a scene for the loading sounds good.
As you're working in a UINavigationController stack here, when you're ready to trigger the segue to the next screen you should pop the loading view controller from the stack without animation, then trigger the segue:
[self.navigationController popViewControllerAnimated:NO];
// now trigger the segue

Resources