gpt4 book ai didi

ios - 如何识别应用程序进入后台的方式?

转载 作者:搜寻专家 更新时间:2023-10-31 23:05:02 26 4
gpt4 key购买 nike

据我所知,目前有两种方法可以让应用进入后台:

1) 用户按下主页按钮

2) 应用已经离开了一段时间,用户没有任何操作,设备睡着了

这两个结果合二为一 - applicationDidEnterBackground 方法被调用,应用程序状态变为 UIApplicationState.Background。那么我怎么知道这到底是怎么发生的呢?我知道这是可能的,因为我眼前有一个应用程序,它会根据用户是否按下主页按钮采取不同的操作。有什么想法吗,伙计们?

最佳答案

据我所知(相信我,我已经尝试过),没有正式的公共(public) API 允许您执行此操作。但是,我发现了这个 GitHub repo ,您应该特别查看的文件是 app delegate implementation file .

repo 说:

This project describes how to detect when a user presses the home button to leave your application and when they press the lock button to put your app into the background.

It utilizes CSNotificationCenter to detect Darwin notifications.

This user在 Stack Overflow 上回答了两个与此相关的问题, repo 似乎基于:

Differentiate between screen lock and home button press on iOS7

How to differentiate between screen lock and home button press on iOS5?

老实说,我不知道 Apple 会拒绝还是接受这个实现。如果您最终以某种方式使用它,请告诉我。我也相信这是 iOS 7 及更高版本。

关于ios - 如何识别应用程序进入后台的方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26083933/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com