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 8547763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:20:14+00:00 2026-06-11T13:20:14+00:00

sorry for the question.I have to save the time when the button is clicked

  • 0

sorry for the question.I have to save the time when the button is clicked for

the first time and then compare the time with the future time and if it is greater than or

equal to the same time I have to fire a method or else an alert.

Here is the code.

-(IBAction)checkInButtonClicked
{
    now = [NSDate date];
   [[NSUserDefaults standardUserDefaults]setObject:now forKey:@"theFutureDate"];

    NSTimeInterval timeToAddInDays = 60 * 60 * 24;
    theFutureDate = [now dateByAddingTimeInterval:timeToAddInDays];

    switch ([now compare:theFutureDate]){
    case NSOrderedAscending:{
    NSLog(@"NSOrderedAscending");

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:
    [NSString stringWithFormat:@"Oops! The Check In will activate after 24Hrs"] 
    delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil ];
    [alert show];
    }
    break;
    case NSOrderedSame:{
    NSLog(@"NSOrderedSame");
    [self insertPoints];
   }
    break;
    case NSOrderedDescending:{
    NSLog(@"NSOrderedDescending");
   }
    break;
   }
  }

But this code is not working exactly.Can anyone please help me out.

Thanks in advance.

  • 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-06-11T13:20:15+00:00Added an answer on June 11, 2026 at 1:20 pm

    The problem is that you’re comparing always now with a future date. That comparison has always the same result.

    If I understood correctly you want exactly the other way around. You must compare now with the first time the user clicked the button. So you set the date in NSUserDefaults only the first time and make comparisons the second and subsequent times.

    - (IBAction)checkInButtonClicked {     
        NSDate *now = [NSDate date];
        NSDate *firstTimeClicked = [[NSUserDefaults standardUserDefaults] objectForKey:@"firstTimeClicked"];
        if (firstTimeClicked) {
            /* this is at least the second time the button has been clicked */        
            NSTimeInterval delta = [now timeIntervalSinceDate:firstTimeClicked];
            if (delta > 24 * 3600) {
                /* button clicked > 1 day ago */
            } else {
                /* button clicked <= 1 day ago */
            }
        } else {
            /* not present in NSUserDefaults, it's first click */
            [[NSUserDefaults standardUserDefaults] setObject:now forKey:@"firstTimeClicked"];   
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It is the first time I ask a question on this forum. Sorry if
Using MVC3 for the first time, so sorry for the noob-like question. I'm trying
I am first time asking question here, sorry, but I can not find similar
I am sorry for the dumb question I have been trying for a while
Quick question (and sorry if it's already been asked, I have looked but couldn't
I'm sorry to ask this question but I have spent hours trying to understand
Hello guys sorry if the question looks stupid to you. i have 3 tables
Sorry about the extremely vague question title (any suggestions for improvements welcome) I have
Sorry for a pretty specific question. I have a table (see bottom), and when
Sorry for a badly-phrased question. I have a requirement coming from a non-technical person

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.