1

每当我第一次在手机上配置我的应用程序时,无论我以哪个用户身份登录,这就是保持登录状态的用户名。即使我终止我的应用程序并重新启动它,登录屏幕也会重新出现,但无论我输入什么凭据在,它是我在第一次配置应用程序时第一次使用的原始用户名,它是真正登录的(我的 SQL 数据库证实了这一点)。

当有人终止应用程序(不是点击“主页”按钮,而是从字面上关闭应用程序在后台运行)时,是否有终止用户会话并将其注销?

同样,一旦我弄清楚这一点,如果应用程序仍在其设备的后台运行并且尚未完全终止,是否无论如何都不会调出我的登录视图控制器?

最好使用确切的代码作为答案...

4

2 回答 2

2

推荐你看看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 问题中的回答的 3 个步骤。

您还可以在UIApplicationDelegate 协议参考中看到有用的信息。

于 2012-05-06T16:57:33.080 回答
0

在以下委托方法中执行注销过程。它可能会帮助你..

   `- (void)applicationWillTerminate:(UIApplication *)application`
于 2012-05-06T15:41:08.303 回答