UIWindow + lockscreen issue - ios

straight to the point: Our app has UITableView with UITableViewCell that has AVPlayerViewController inside (its view) + custom video controls. One of the controls is fullscreen mode. Note that everything works perfectly - loading video, reusing, even the fullscreen.
Fullscreen functionality is based on creating new UIWindow, setting its rootViewController to the videoplayer and making it keyAndVisible - basically showing fullscreen AVPlayerViewController from cell subview on tap
The issue comes when user locks his device - after unlocking, the fullscreen window "disappears" and app is frozen / stuck on previous screen (the list with video cell, text cells.. - the one that made the new UIWindow)
The UIWindow (video window) is there, but without content (no subviews, VCs..) on top of the main (app, tableview list..) UIWindow - refer to pictures.
This issue is not happening on Simulator - only real devices.
View hierarchy debug before locking the device and showing the video on fullscreen (with new UIWindow):
View hierarchy debug after unlocking the device and app freezing on previous UIWindow:
Is there any possible fix? Or a better way of presenting AVPlayerViewController from UITableViewCell (while playing and without stopping the video)?
Note: the bug happens even if we remove landscape / portrait orientation changing, the issue seems to be related to UIWindow
PS: sorry for hiding the names in the pictures - NDA...

Related

Tapping preview in context menu on iPad doesn't animate presentation of full screen view controller

I have a context menu in my app that shows a photo preview above the actions, and tapping the preview presents that view controller full-screen. On iPhone, when you tap the preview there’s a lovely animation - it bounces into full screen. But on iPad, when you tap the preview the context menu dismisses and then the screen appears without any animation.
This is the (new*) default behavior on iPad. The idea being you can use your own presentation animation. To get the system "pop" style that's default on iPhone, set the preferredCommitStyle to .pop on the UIContextMenuInteractionCommitAnimating object.
*I think it changed in iOS 13.4. This change broke the Photos app as well. 😅

Delegate fullscreen event AVPlayer objective-c

After several sleepless nights, I don't have any more ideas how to do what I am trying to do.
In short words, I am trying to allow my fullscreen video to be accessible in all orientations (landscape and portrait). This is the only place in the app where I want to allow that. All other views are locked to portrait.
My idea was to delegate fullscreen enter / exit event and in that place, programmatically set orientation allowance, so on fullscreen enter, unlock landscape additionally and on fullscreen exit, lock back only to portrait. Everything works fine apart from the one crucial part...I can not delegate fullscreen enter/exit event (delegating those events was my idea but I might be completely wrong and that should be managed in completely different way)
I am using this library: https://github.com/brentvatne/react-native-video
Thanks in advance for any help!

view controller state after mpmovieplayercontroller full screen mode iOS

i have taken a .Storyboard Project and for video playing i am using separate .XIB file.
When i add a view player xib on my storyboard content view, it played video well
But, when i enter to fullscreen mode and come back, content of the previous view is getting clear/nil.
Can anybody help!
Thanks
it seems like you are loosing strong references to you view controller contents . make them strong to keep the reference.
example-
property(nonatomic, strong) UIImageView *imageView;// for example only
by this you will not loose this object(imageView) until the controller is present in memory.
i don't know without your code. so what you have mistaken. here is my guessing answer for you
fullscreen
A Boolean that indicates whether the movie player is in full-screen mode.
#property (nonatomic, getter=isFullscreen) BOOL fullscreen
Discussion
The default value of this property is NO. Changing the value of this property causes the movie player to enter or exit full-screen mode immediately. If you want to animate the transition to full-screen mode, use the setFullscreen:animated: method instead.
Whenever the movie player enters or exits full-screen mode, it posts appropriate notifications to reflect the change. For example, upon entering full-screen mode, it posts MPMoviePlayerWillEnterFullscreenNotification and MPMoviePlayerDidEnterFullscreenNotification notifications. Upon exiting from full-screen mode, it posts MPMoviePlayerWillExitFullscreenNotification and MPMoviePlayerDidExitFullscreenNotification notifications.
The value of this property may also change as a result of the user interacting with the movie player controls.
reference by apple doc

UIAlertViews, UIActionSheets and keyWindow problems

I created an iOS 7 passcode replica and I have this problem I can't seem to solve. I need the lock screen view to be on top of everything else, so the app is covered in iOS' multitasking view, so I add it directly to the keyWindow. Everything fine so far.
The problem arises if there's an alertView or actionSheet (will only mention alertViews in this post, to keep it simple) open when I have to display the lock screen. It has been answered several times that there are no references to alertViews in iOS 7, which is true, and the window in which they are displayed is _UIModalItemHostingWindow, which has 2 UIViews, indeed with no reference to the alertView.
This _UIModalItemHostingWindow also becomes the new keyWindow, so it's on top of everything else, but it can not be found in [UIApplication sharedApplication].windows meaning if I add the lock screen to my former keyWindow (the default keyWindow, if you will), it will be beneath the alertView and its dimmed background, so the user can't interact with the lock screen before dismissing the alertView. The other option is detailed a bit further below.
The lock screen works like this: on applicationDidEnterBackground it checks if the passcode is enabled; if it is enabled and the passcode duration is 0 (user selected to lock the app immediately), it adds the lock screen now, so it covers the app in the multitasking view. Now, the option I mentioned above is to add the alertView to this _UIModalItemHostingWindow window, but when returning to the app, the lock screen view is displayed with a 1+ second delay (even though I added it before I went to background!) and the app isn't covered by anything in the multitasking view. (Currently it's displayed in the wrong position too, if you go ahead and download it, that is fixed, but I didn't pushed the commit yet).
I tried hiding and removeFromSuperview this _UIModalItemHostingWindow, but when coming back to the app, the alertView animation still runs as if it was just fired. I suspect the delay mentioned above also happens due to how Apple handles alertViews when coming back to foreground.
I also tried creating a new window and to make that the new keyWindow, but same thing happens.
Here's a small discussion about this, covering all the stuff I tried, maybe I missed something in this post.
https://github.com/rolandleth/LTHPasscodeViewController/issues/16
Any ideas? Except creating manual references to every alertView and actionSheet inside my app, because I'm trying to find a fix for the passcode library, not my own apps; I can find dirty workarounds for that, no problem :)
Update: The window is _UIAlertOverlayWindow if an actionSheet is used instead of an alertView, but it behaves the same as far as I can tell.
The simplest solution is to have a lockscreen window instead of a lockscreen view.
Create a new UIWindow, set its frame to UIScreen bounds, put a simple rootViewController there that should handle rotation and display your "lock screen" views and set the windowLevel to UIWindowLevelAlert + 1.
Then set window's hidden to YES. Whenewer you want to show the lockscreen, just set hidden to NO.
I guess that adding a view to keyWindow also doesn't work when a popover/action sheet is displayed and also when a keyboard is displayed (keyboard has its own window on top of the key window).

MPMoviePlayerController done button, Landscape orientation

I'm using simple MPMoviePlayerController. In portrait mode it is emmbedded into my layout. When I rotate my device I want it to go full screen. In full screen mode there is a done button but only thing it does is pausing the video. I want to dismiss modal view controller when the done button is tapped. How can I do this?
I've tried:
Putting a [UIColor clearColor] on a background of a button and place a button over Done button thus intercept touch event into my own selector. It failed because my custom button isn't displayed when MPMoviePlayerController is in fullscreen mode.
Going to notification center and trying to catch "willExitFullscreen" but it won't occur (pressing done button when in landscape fullscreen mode isn't goint out from the fullscreen mode).
Finding done button in the MPMoviePlayerController... but I was unable to find it.
Using MPMoviePlayerViewController isn't an option as I want to be able to use embedded player in my controller when i Portrait mode, and be able to rotate movie without loading it from scratch (so pushing new controller when user changes device orientation isn't right solution for me).
I've read a few topics on this issue and question can be the same or similar but anserws require either things I've checked (i.e. notifications) or things I can't use (MPMoviePlayerViewController).
ANSWER (as I am unable to post it in 7h)
Heh ok..
The culprit of this whole mess was this line of code
[self.mpPlayer setControlStyle:MPMovieControlStyleFullscreen];
So it seems that setting Fullscreen control style when going into fullscreen mode will break done button....
Makes no sense to me. But when I commented out this line I am able to recive willExitFullscreen notification and I can work with that.
The culprit of this whole mess was this line of code
[self.mpPlayer setControlStyle:MPMovieControlStyleFullscreen];
So it seems that setting Fullscreen control style when going into fullscreen mode will break done button....
Makes no sense to me. But when I commented out this line I am able to recive willExitFullscreen notification and I can work with that.

Resources