In iOS 13, what events do I get when the user swipes my app up in the app switcher?

旧城冷巷雨未停 提交于 2019-12-11 10:48:23

问题


I'm finding it extraordinarily difficult to categorize and account for what events I get (or don't get) when the user swipes my app up in the app switcher on iOS 13. This seems to be because of changes caused by the multiple scene support. What are the events that I get in that situation?


回答1:


Let's assume that your app supports window scenes. So what the user is swiping up in the app switcher is really a scene, not your app as a whole. Then the possibilities appear to be as follows.

On an iPhone

If the scene was frontmost:

  • sceneDidEnterBackground
  • applicationWillTerminate(_:)

But if the scene was not frontmost, you'll get nothing; you already received sceneDidEnterBackground, and you won't get applicationWillTerminate(_:) now because the app isn't running.

On an iPad, if the app does not support multiple windows

If the scene was frontmost:

  • sceneDidDisconnect(_:)
  • application(_:didDiscardSceneSessions:)
  • applicationWillTerminate(_:)

But if the scene was not frontmost, you'll get nothing; you already received sceneDidEnterBackground, and you won't get applicationWillTerminate(_:) now because the app isn't running.

On an iPad, if the app does support multiple windows

If the scene was frontmost:

  • sceneDidEnterBackground
  • applicationWillTerminate(_:) (perhaps)

But if the scene was not frontmost, you'll get nothing; you already received sceneDidEnterBackground, and you won't get applicationWillTerminate(_:) now because either the app isn't running or the app isn't terminating (if there's another window). If the app is still running, you might get sceneDidDisconnect(_:) and possibly application(_:didDiscardSceneSessions:) later.


Conclusions

What's the odd-man-out here? It's the case where we're running on an iPad and we support scenes but not multiple windows. We don't get sceneDidEnterBackground! I regard that as incoherent. Since we don't support multiple windows, this is basically an iPhone app and it should behave like an iPhone app. I shouldn't have to double up my code just because my app runs on both iPhone and iPad.



来源:https://stackoverflow.com/questions/58573015/in-ios-13-what-events-do-i-get-when-the-user-swipes-my-app-up-in-the-app-switch

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