在iOS中实现从服务器注销(计时器事件)

在iOS中实现从服务器注销(计时器事件),ios,nstimer,Ios,Nstimer,我试图在iPad中实现用户从服务器自动注销。这是我的前辈一直在使用的代码 - (void) Logout:(id) sender { @autoreleasepool { NSDate *date = [NSDate dateWithTimeIntervalSinceNow:logoutUser]; if (timerLogout) { [timerLogout invalidate];

我试图在iPad中实现用户从服务器自动注销。这是我的前辈一直在使用的代码

- (void) Logout:(id) sender
{
    @autoreleasepool
    {   
        NSDate *date    = [NSDate dateWithTimeIntervalSinceNow:logoutUser];
        if (timerLogout) {
            [timerLogout invalidate];
            timerLogout = nil;
        }
        timerLogout = [[NSTimer alloc] initWithFireDate:date interval:logoutUser target:self selector:@selector(CallToLogout:) userInfo:nil repeats:NO];

        NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
        [runLoop addTimer:timerLogout forMode:NSRunLoopCommonModes];
        [runLoop run];
    }
}
我面临的问题是,例如,当自动注销的时间为60分钟时,iPad从服务器上注销的时间约为20分钟。。不知道为什么会这样


如果需要更多信息,我可以提供。。需要一些指导。

有点奇怪,他不是简单地使用
scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:
NSTimer
上的类方法(它会自动将它添加到运行循环中),但我想这也会做同样的事情,是吗D-添加
NSLog
并检查
注销方法中的
日期是否正确。-添加
NSLog
并查看调用
CallToLogout
的频率/时间。-此外,您的代码的任何其他部分是否可以调用
CallToLogout
(假设这是唯一的注销方法)?您如何知道iPad在20分钟后从服务器注销?您的应用程序在20分钟后是否调用了
CallToLogout:
方法?或者,您是否正在丢失会话(在这种情况下,可能是服务器端的持久性问题)?我的代码中只有一部分会注销用户,即CallToLogout->它会生成一个警报,表明您已注销…只有一个对CallToLogout的函数调用。。。