how to detect idle user in iphone-sdk

坚强是说给别人听的谎言 提交于 2020-01-02 07:16:28

问题


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


回答1:


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.




回答2:


Try this out

-(void)applicationWillResignActive:(UIApplication *)application

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


来源:https://stackoverflow.com/questions/3101345/how-to-detect-idle-user-in-iphone-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!