In my Application I want to call Logout Function if user is idle for certain amount of time how to accomplish
在我的应用程序中,如果用户空闲了一定时间,我想调用Logout函数
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
这个答案对我iPhone不起作用:如果我从UIApplication将我的app委托类子类化并实现,检测用户自上次触摸以来的不活动/空闲时间
- (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
我找不到UIApplication的另一个实例
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
谢谢
2 个解决方案
#1
2
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
.
您的应用程序类也是一个应用程序委托类——这很糟糕。UIApplicationMain()将创建自定义应用程序子类的一个实例,然后该实例将尝试其委托的一个实例——它也是自定义应用程序子类的一个实例。您应该将这些关注点分离——是的,您的自定义应用程序子类需要子类化UIApplication,但是您的应用程序委托应该是一个单独的类,子类NSObject。
#2
0
Try this out
试一试
-(void)applicationWillResignActive:(UIApplication *)application
{
NSLog(@"Application not Active");
// FETCH THE CURRENT TIME
}
#1
2
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
.
您的应用程序类也是一个应用程序委托类——这很糟糕。UIApplicationMain()将创建自定义应用程序子类的一个实例,然后该实例将尝试其委托的一个实例——它也是自定义应用程序子类的一个实例。您应该将这些关注点分离——是的,您的自定义应用程序子类需要子类化UIApplication,但是您的应用程序委托应该是一个单独的类,子类NSObject。
#2
0
Try this out
试一试
-(void)applicationWillResignActive:(UIApplication *)application
{
NSLog(@"Application not Active");
// FETCH THE CURRENT TIME
}