如何在iphone-sdk中检测空闲用户

发布于 2024-09-06 21:08:29 字数 1070 浏览 12 评论 0原文

在我的应用程序中,如果用户闲置一段时间,我想调用注销功能,如何完成

这个答案对我来说不起作用 iPhone:检测自上次屏幕触摸以来用户不活动/空闲时间 如果我从 UIApplication 子类化我的应用程序委托类并实现

- (void)sendEvent:(UIEvent *)event

它会给我错误,

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'There can only be one UIApplication instance.'

我在应用程序中找不到 UIApplication 的其他实例,

到目前为止

而不是

@interface IdleAppDelegate : NSObject <UIApplicationDelegate> {

我已将其更改为

@interface IdleAppDelegate : UIApplication<UIApplicationDelegate> {

and in main 而不是

 int retVal = UIApplicationMain(argc, argv, nil, nil);

我已更改还有

int retVal = UIApplicationMain(argc, argv, @"IdleAppDelegate", @"IdleAppDelegate");

什么事情要做吗?

我收到上述错误...我错过了什么吗...?

请帮忙

谢谢

In my Application I want to call Logout Function if user is idle for certain amount of time how to accomplish

this answer doesn't work for me
iPhone: Detecting user inactivity/idle time since last screen touch
if i subclass my app delegate class from UIApplication and implement

- (void)sendEvent:(UIEvent *)event

It gives me error

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'There can only be one UIApplication instance.'

I can't find the other instance of UIApplication in my application

so far i have done

instead of

@interface IdleAppDelegate : NSObject <UIApplicationDelegate> {

I have changed it to

@interface IdleAppDelegate : UIApplication<UIApplicationDelegate> {

and in the main instead of

 int retVal = UIApplicationMain(argc, argv, nil, nil);

I've changed it to

int retVal = UIApplicationMain(argc, argv, @"IdleAppDelegate", @"IdleAppDelegate");

Is there anything remaining to do?

I'm getting the above error... am I missing something...?

Please Help

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

澜川若宁 2024-09-13 21:08:29

您的应用程序类也是一个应用程序委托类 - 这很糟糕。 UIApplicationMain() 将创建自定义应用程序子类的实例,然后该子类将尝试其委托的实例 - 这也是自定义应用程序子类的实例。您应该将这些问题分开 - 是的,您的自定义应用程序子类需要子类化 UIApplication,但您的应用程序委托应该是一个单独的类,它是 NSObject 子类化。

Your application class is also an application delegate class - that's bad. UIApplicationMain() will create an instance of your custom application subclass, which will then try to an instance of its delegate - which is also an instance of your custom application subclass. You should separate these concerns - yes your custom app subclass needs to subclass UIApplication, but your app delegate should be a separate class that subclasses NSObject.

清浅ˋ旧时光 2024-09-13 21:08:29

试试这个

-(void)applicationWillResignActive:(UIApplication *)application

{
    NSLog(@"Application not Active");
    // FETCH THE CURRENT TIME 
}

Try this out

-(void)applicationWillResignActive:(UIApplication *)application

{
    NSLog(@"Application not Active");
    // FETCH THE CURRENT TIME 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文