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

社会主义新天地 提交于 2021-02-17 15:24:49

问题


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 to use the techniques that check frame size from iOS 9 to detect if another app is a "slide over" over my app.

Is there any new method to detect if another app is running as slide over?


回答1:


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.



来源:https://stackoverflow.com/questions/46442761/how-to-detect-if-another-app-is-running-as-slide-over-in-ios-11

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!