iOS:在离开屏幕时终止应用程序 [英] iOS: Making an App terminate when leave screen

查看:111
本文介绍了iOS:在离开屏幕时终止应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了一个简单的应用程序,用硬件激活一些东西,并不重要。

I've build a simple app activating something in hardware, not important.

现在我只想让应用程序在用户离开屏幕时完全终止,交换机应用程序,接听电话,按主页按钮等等。

Now I just want the app to terminate completely if the user leaves the screen, switches apps, gets a call, press the home button, etc.

我被所有应用程序状态混淆了,我找不到合适的地方来处理它。
我想我需要听一个进入睡眠事件并发出终止命令(退出!)
或类似的东西。

I'm all mixed up by all the application states, I couldn't find the right place to handle it. I guess I need to listen to an "going to sleep" event and put a termination command (exit!) or something like that.

推荐答案

这比人们想象的要容易。

This is easier than what one might think.

在你的应用程序的plist文件中定义(检查)选项应用程序没有在后台运行( UIApplicationExitsOnSuspend ),你就完成了。

In your app's plist file define (check) the option "Application does not run in background" (UIApplicationExitsOnSuspend), and you are done.

这篇关于iOS:在离开屏幕时终止应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆