在屏幕变为黑色后不活动,调用什么方法? [英] What method is called before the screen goes black after inactivity?

查看:163
本文介绍了在屏幕变为黑色后不活动,调用什么方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在应用程式关闭前执行一些方法,因为使用者没有活动(例如萤幕变黑,手机在您未触碰一段时间后已锁定)。在发生这种情况时,会调用什么方法?



我猜猜:




  • 此方法/这些方法将是我的AppDelegate类的一部分。

  • 此方法/这些方法类似于 - [UIAppDelegate applicationWillResignActive:] - [UIAppDelegate applicationDidEnterBackground:] - [UIAppDelegate willTerminate:] li>


我在UIApplicationDelegate的文档中没有看到任何内容,我有困难Googling正确的术语(例如,方法不活动应用目标c )。我也没有在Stack Overflow上看到任何内容。






EDIT / CLARIFICATION 指示我向下面的堆栈溢出帖子作为可能的重复: iPhone:检测上次屏幕触摸后的用户闲置/空闲时间



但是,我相信我的问题是非常不同的。




  • 我的问题:是否有 - 在Objective-C中的方法类似于 - [UIAppDelegate applicationWillResignActive:] 等。

  • 其他问题:如何触发在预定时段的用户不活动之后,不管屏幕状态如何?



我可以看到其他问题如何回答我的问题if有一种方法用于获得用户在设置(1分钟,2分钟,3分钟,4分钟,5分钟或从不)下为自动锁定设置的时间长度,但我没有看到UIApplication的文档中的方法或属性。我假设一个妥协是假设屏幕在不活动1分钟后关闭,但这对我来说是不太可取的假设。

解决方案

当应用程序即将变为非活动状态时,将调用此方法(您应该立即停止此处的任何进程,如计时器等)



<$ p $当它已经变为非活动状态时,您可以使用

[UIAppDelegate applicationWillResignActive:]



<应保存任何重要数据)

   -  [UIAppDelegate applicationDidEnterBackground:] 
pre>

当您的应用程式遭到杀死时(全部储存,全部杀掉)

   -  [UIAppDelegate willTerminate:] 

/ p>

https://developer.apple.com/library/ios/documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html


I'd like to perform some methods before my app closes due to user inactivity (i.e., the screen going black and the phone locking when you haven't touched it for a while). What method(s) is/are called when this happens?

I'm guessing:

  • This method / these methods would be part of my AppDelegate class.
  • This method / these methods would be analogous to -[UIAppDelegate applicationWillResignActive:], -[UIAppDelegate applicationDidEnterBackground:], -[UIAppDelegate willTerminate:].

I didn't see anything in the documentation for UIApplicationDelegate and I had difficulty Googling the right terms (e.g., "method inactivity app objective c"). I also didn't see anything on Stack Overflow.


EDIT / CLARIFICATION: Multiple people have directed me towards the following Stack Overflow post as a possible duplicate: iPhone: Detecting user inactivity/idle time since last screen touch

However, I do believe my question is very different. Please let me know what I am misunderstanding if my understanding is off.

  • My question: Is there a built-in method in Objective-C akin to -[UIAppDelegate applicationWillResignActive:] et al. that is called or property that is changed when the screen turns black after a period of inactivity while an app is still open?
  • Other question: How can I trigger a method after a predetermined period of user inactivity, regardless of screen state?

I could see how the other question could answer my question if there is a method for obtaining the length of time the user has set for "Auto-Lock" under Settings (either 1 min, 2 min, 3 min, 4 min, 5 min, or Never), but I don't see such a method or property in the documentation for UIApplication. I suppose a compromise would be to assume that the screen is "off" after 1 minute of inactivity, but this to me would be a less-than-desireable assumption.

解决方案

This one is invoked when the app is about to become inactive (you shouldstop any process here like timers etc..)

[UIAppDelegate applicationWillResignActive:]

when it has already become inactive (you should save any important data here)

-[UIAppDelegate applicationDidEnterBackground:]

when your app is killed (save all , kill em all)

-[UIAppDelegate willTerminate:]

for any other info.. you can check this link

https://developer.apple.com/library/ios/documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html

这篇关于在屏幕变为黑色后不活动,调用什么方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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