3

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

Community
  • 1
  • 1
Mihir Mehta
  • 13,743
  • 3
  • 64
  • 88
  • Maybe you didn't subclass it right? See: http://stackoverflow.com/questions/1399202/how-to-subclass-uiapplication – NG. Jun 23 '10 at 12:34
  • Thanks for you comment... But i have implemented this way only I have inherited my appDelegate class from UIApplication and in inside main I have written int retVal = UIApplicationMain(argc, argv, appClass, delegateClass); also where appClass is the name of my appDelegate Class – Mihir Mehta Jun 23 '10 at 12:42
  • I have edited the question and put the code of how i subclass it... – Mihir Mehta Jun 24 '10 at 05:05

2 Answers2

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.

0

Try this out

-(void)applicationWillResignActive:(UIApplication *)application

{
    NSLog(@"Application not Active");
    // FETCH THE CURRENT TIME 
}
Ben Zotto
  • 70,108
  • 23
  • 141
  • 204
Suresh Varma
  • 9,750
  • 1
  • 60
  • 91
  • Thanks but... It will getting called when application itself become inactive... like when incoming call OR receiving SMS etc... Not fulfilling my requirement – Mihir Mehta Jun 23 '10 at 12:53