How to detect if another app is running as slide over in iOS 11?

前端 未结 1 1964
难免孤独
难免孤独 2021-02-04 07:57

The multitasking features got updates in iOS 11, one of those was slide over which is demonstrated in the gif below.

With these changes it\'s no longer possible

相关标签:
1条回答
  • 2021-02-04 08:23

    I was able to get this working fairly easily on an iPad Pro (which supports side-by-side apps, not just slide-overs). Here's the code:

    class ViewController: UIViewController {
    
        override func viewWillLayoutSubviews() {
            isThisAppFullScreen()
        }
    
        @discardableResult func isThisAppFullScreen() -> Bool {
            let isFullScreen = UIApplication.shared.keyWindow?.frame == UIScreen.main.bounds
            print("\(#function) - \(isFullScreen)")
            return isFullScreen
        }
    }
    

    The end result is that it will print "true" if the view is full screen and "false" if it's sharing the screen with another app, and this is run every time anything is shown, hidden, or resized.

    The problem then is older devices that only support slide-over. With these, your app is not being resized anymore. Instead, it's just resigning active use and the other app is becoming active.

    In this case, all you can do is put logic in the AppDelegate to look for applicationWillResignActive and applicationDidBecomeActive. When you slide-over, you get applicationWillResignActive but not applicationDidEnterBackground.

    You could look for this as a possibility, but you cannot distinguish between a slide-over and a look at the Notifications from sliding down from the top of the screen. It's not ideal for that reason, but monitoring application lifecycle is probably the best you can do.

    0 讨论(0)
提交回复
热议问题