1

I have implemented a autologin screen in my application which comes up first if user has saved his credentials. On that screen there is a Cancel button, for which user has a choice if he wants to cancel the autologin and wants to enter different credentials on the login screen.

I am calling the web services in the viewDidLoad and it takes around 1 second to get login automatically due to which user does not gets time to cancel the process.

I want to know if there is any solution we could hold the web services call for around 3-4 seconds so that the user would get time for cancel and then web services get called.

Any help appreciated, thanx

Omer Waqas Khan
  • 2,423
  • 4
  • 33
  • 62

2 Answers2

2

Yes, you could use an NSTimer instead of just invoking your service call instantly.

See How do I use NSTimer? for further instructions on how to use it.

Example:

// define a timer as instance variable in your .h file
NSTimer *_loginTimer;


// use timer in your .m file
- (void) viewDidLoad {
    // initialize timer (3 seconds)
    _loginTimer = [[NSTimer scheduledTimerWithTimeInterval:3.0
        target:self
        selector:@selector(doAutoLogin)
        userInfo:nil
        repeats:NO] retain];
}

- (void) doAutoLogin {
    // request to perform login
}

- (void) cancelAutoLogin {
    // invalidate timer
    [_loginTimer invalidate];
    _loginTimer = nil;
}
Community
  • 1
  • 1
Kristofer Sommestad
  • 3,061
  • 27
  • 39
0

you can use

-(void)viewDidLoad
{
    [self performSelector:@selector(doAutoLogin) withObject:nil afterDelay:3];
}

- (void) doAutoLogin {
    // request to perform login
}
Krrish
  • 2,256
  • 18
  • 21
  • Actually Krrish, to some extent you are right, but in between of this delay if user presses Cancel autologin button then the user will be taken to Login Screen for changing credentials and at the backend when this method [self performSelector:@selector(doAutoLogin) withObject:nil afterDelay:3]; will complete its delay then application will get autologin and user will be interrupted – Omer Waqas Khan Jan 19 '12 at 12:15