2012-05-06 53 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中查看有用的信息。

相關問題