Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6900965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:36:50+00:00 2026-05-27T07:36:50+00:00

I added this code which functions as an auto timeout in my app. The

  • 0

I added this code which functions as an auto timeout in my app. The userDefaults doubleForKey:@"timeoutLength" should be in minutes. For example, if value is 500, that should mean 500 minutes.

I keep seeming to be hitting the timout loop though even when it hasn’t really been 500 + min. Is anything wrong in my code? Perhaps a minutes/seconds error etc.

    [userDefaults setDouble:[[userContextDictionary valueForKey:@"autologout_idle_timeout"] doubleValue] forKey:@"timeoutLength"];


    double timeDifference = ([[NSDate date] timeIntervalSince1970] - [userDefaults doubleForKey:@"Close Time"]) / 60;

    if (timeDifference > [userDefaults doubleForKey:@"timeoutLength"]) {
        NSLog(@"Timeout Hit");
    } else {
        NSLog(@"No Timeout");
    }

Edit:

- (void)applicationDidEnterBackground:(UIApplication *)application {
    [userDefaults setObject:[NSDate date]  forKey:@"Close Time"];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {   
    [userDefaults setDouble:[[userContextDictionary valueForKey:@"autologout_idle_timeout"] doubleValue] forKey:@"timeoutLength"];  
    //This is an int like 500, or 600, etc. 

    NSDate *closeDate = [userDefaults objectForKey:@"Close Time"]
    NSTimeInterval timeWhenClosedTimeInterval = [closeDate timeIntervalSince1970];
    NSTimeInterval todayTimeInterval = [[NSDate date] timeIntervalSince1970];

    NSTimeInterval timeDifference = ((todayTimeInterval - timeWhenClosedTimeInterval ) / 60);
    if (timeDifference > [userDefaults doubleForKey:@"timeoutLength"]) {
        NSLog(@"Timeout Hit");
    } else {
        NSLog(@"No Timeout");
    }
    return YES;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:36:51+00:00Added an answer on May 27, 2026 at 7:36 am

    NSTimeInterval is expressed in seconds, not minutes.

    Here’s the Apple doc where it’s described.

    I’m not 100% certain what your ultimate problem with, but 500 seconds doesn’t seem like nearly enough time.

    In the meantime, I wrote up some changes to your code to demo for myself:

    NSDate * yesterday = [[NSDate date] dateByAddingTimeInterval: (-1 * 60 * 60 * 24 )];
    NSTimeInterval yesterdayTimeInterval = [yesterday timeIntervalSince1970];
    NSTimeInterval todayTimeInterval = [[NSDate date] timeIntervalSince1970];
    
    // this properly converts timeDifference in seconds to minutes
    NSTimeInterval timeDifference = ((todayTimeInterval - yesterdayTimeInterval ) / 60);
    NSLog( @"time difference is %4.2f", timeDifference );
    

    which came up with 1400 minutes (divided by 60 minutes per hour = 24 hours).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my CMS I've added this code <div><?php include(my_contact_form.php) ?></div> which updates to a
I have added some code which compiles cleanly and have just received this Windows
I have this code $(.delete2).click(function() { $('#load2').fadeIn(); } I have dynamically added item via
I have created a reddot cms component, in which I added this line Also,
I have a few custom UITableViewCells - http://img11.imageshack.us/i/customfacilitiescell.png/ which are added to this UIViewController
I have a C# app for which I've written GDI+ code that uses Bitmap/TextureBrush
Let's say for example that I have two functions with random code inside and
ADDED: This question is now, I believe, subsumed by this one: Using GNU Screen
I just added this to my web.xml on my JBOSS server. But it had
I use DATEDIFF function to filter records added this week only: DATEDIFF(week, DateCreated, GETDATE())

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.