开发者

Auto Log out from an iPhone app (when app goes in the background)

开发者 https://www.devze.com 2023-03-03 19:04 出处:网络
The Settings bundle of my iPhone has the user login and password credentials saved.(similar to the Mail app). The application in its current state does not have a separate login/password view page.

The Settings bundle of my iPhone has the user login and password credentials saved.(similar to the Mail app). The application in its current state does not have a separate login/password view page.

Now, when the app enters the background, I would want it to wait for 40 seconds and after that automatically log off. I found similar posts, and thus found that I could use the methods in the app delegate:

- (void) applicationDidEnterBackground:(UIApplication *)application
{
    currentTimeBackground = CACurrentMediaTime();  
} 

- (void) applicationDidBecomeActive:(UIApplication *)application
{
    currentTimeActive = CACurrentMediaTime();
}

Then I plan to use the bottom logic somewhere in my code to trigger a lo开发者_开发问答gout.

 if ((currentTimeActive - currentTimeBackground)> 40 ) {
           NSLog(@"Need to prompt for re login!");
           // Logic to logout the application.
 }

Now, I found that it is not possible to alter the Settings bundle (.plist) file through a program (at run time). (http://stackoverflow.com/questions/4921890/how-can-i-modify-a-settings-bundle-in-real-time)

So please suggest me how would I log out of this application? This application fetches data from a server (I have a local server set up for development).


Create a background task and have it wait 40 seconds and then log off. If the user re-opens the app, cancel the background task.

0

精彩评论

暂无评论...
验证码 换一张
取 消