2012-05-06 54 views
0

每当我第一次在我的手机上提供我的应用程序时,无论我登录为哪个用户,即保持登录状态的用户名。即使终止我的应用程序并将其恢复,登录屏幕也会恢复,但无论凭据是凭据我放入,它是我第一次使用时初次使用的真正登录的原始用户名(我的SQL数据库证实了这一点)。如何在iPhone应用程序终止时注销用户?

有没有办法终止用户会话,并在有人终止应用程序时注销它们(不是击中“主页”按钮,而是从后台运行中逐字地关闭应用程序)?

同样,一旦我弄清楚了,有没有反正不带我的登录视图控制器,如果应用程序仍在设备的后台运行,并没有完全终止?

确切的代码是优选的答案...

回答

0

做以下的委托方法注销过程。它可能会帮助你..

`- (void)applicationWillTerminate:(UIApplication *)application` 
1

我建议你看看UIApplicationDelegate。有许多有趣的委托方法来处理您的应用程序状态。当然,你可以在任何ViewController中实现这些方法。让我们看看那里。

- (void)applicationWillResignActive:(UIApplication *)application 
{ 
    /* 
    Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 
    Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 
    */ 
} 

- (void)applicationDidEnterBackground:(UIApplication *)application 
{ 
    /* 
    Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 
    */ 
} 

- (void)applicationWillEnterForeground:(UIApplication *)application 
{ 
    /* 
    Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 
    */ 
} 

- (void)applicationDidBecomeActive:(UIApplication *)application 
{ 
    /* 
    Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 
    */ 
} 

- (void)applicationWillTerminate:(UIApplication *)application 
{ 
    /* 
    Called when the application is about to terminate. 
    Save data if appropriate. 
    See also applicationDidEnterBackground:. 
    */ 
} 

你的问题:

反正是有终止用户会话,并记录他们出来的时候有人终止应用程序(不打“家”按钮,但字面上关闭从应用程序在后台运行)?

当然,你可以实现的方法来清除用户会话和日志出来(如果你在一个模式去做,这将是巨大的,在任何的ViewController这些情况来处理)

同样,一旦我弄清楚了,如果应用程序仍在设备的后台运行并且尚未完全终止,那么是否还有无法启动我的登录视图控制器?

你应该从我的答案处理其他StackOverflow问题here

您还可以在UIApplicationDelegate Protocol Reference中查看有用的信息。

相关问题