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

  • Home
  • SEARCH
  • 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 3980948
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:21:05+00:00 2026-05-20T05:21:05+00:00

I schedule a Notification, and give it 60 minutes warning before it should display

  • 0

I schedule a Notification, and give it 60 minutes warning before it should display an alert message…

As soon as I add the notification the method in my App Delegate is called:

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification

How can I know that it will show up in the background as an alert? Is there any other Delegate method I need to override or use in order to ensure that given a scheduled Alert with a 60 Minute Interval…

- (void)scheduleNotificationWithItem:(NSDate *)item interval:(int)minutesBefore
{   
    NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];

    NSDateComponents *dateComps = [[NSDateComponents alloc] init];
    //NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

    NSDateComponents *currentDateComponents = [calendar components:( NSWeekdayCalendarUnit | 
                                                                     NSYearCalendarUnit | NSMonthCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSWeekCalendarUnit | NSMinuteCalendarUnit) fromDate:item];

    NSLog(@"- current components year = %i , month = %i , week = % i, weekday = %i", [currentDateComponents year], [currentDateComponents month], [currentDateComponents week], [currentDateComponents weekday]);

    NSLog(@"[currentDateComponents minute]: %i",    [currentDateComponents minute]);
    NSLog(@"[currentDateComponents hour]: %i",      [currentDateComponents hour]);
    NSLog(@"[currentDateComponents day]: %i",       [currentDateComponents day]);
    NSLog(@"[currentDateComponents week]: %i",      [currentDateComponents week]);
    NSLog(@"[currentDateComponents month]: %i",     [currentDateComponents month]);
    NSLog(@"[currentDateComponents year]: %i",      [currentDateComponents year]);

    [dateComps setDay: [currentDateComponents day]];

    [dateComps setMonth:[currentDateComponents month]];

    [dateComps setYear:[currentDateComponents year]];

    [dateComps setHour:[currentDateComponents hour]];

    [dateComps setMinute:[currentDateComponents minute]];

    NSDate *itemDate = [calendar dateFromComponents:dateComps];

    [dateComps release];

    UILocalNotification *localNotif = [[UILocalNotification alloc] init];

    if (localNotif == nil)
        return;

    localNotif.fireDate = [itemDate addTimeInterval:-(minutesBefore*60)];

    localNotif.timeZone = [NSTimeZone defaultTimeZone];

    localNotif.alertBody = [NSString stringWithFormat:@"%@\n%@",
                            streetAddress,
                            stringOfWhenAuctionIsOn];

    localNotif.alertAction = NSLocalizedString(@"View Details", nil);

    localNotif.soundName = UILocalNotificationDefaultSoundName;

    localNotif.applicationIconBadgeNumber = 1;

    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:streetAddress
                                                         forKey:idOfStreetAlert];

    localNotif.userInfo = infoDict;

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
  • 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-20T05:21:05+00:00Added an answer on May 20, 2026 at 5:21 am

    If the notification shows up right away there probably is something wrong with your fireDate property. It looks like you are trying to verify that the date sent is correct but you should also verify that that fireDate is what you expect.

    Also, you could perhaps do

    localNotif.fireDate = [item dateByAddingTimeInterval:-60*minutesBefore];
    

    to achieve the same effect and don’t have to mess around with NSDateComponents. I have not tested this but it might work.

    As for what happens when the timer fires and your app is not running. If the app has not been terminated application:didReceiveLocalNotification: will get called. If on the other side your app has been terminated you need to check in application:didFinishLaunchingWithOptions: as pointed out by @Ishu. I usually just pass the notification to a common method to avoid duplicating the code.

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

Sidebar

Related Questions

I have a new earthquake notification android app thats in it's initial release version.
I am handling local notifications using: - (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif And to schedule
How do you schedule a Windows Mobile application to periodically start up to perform
How do you schedule a task in Windows XP to run when you shut
Hi I'd like to schedule an existing job in the Sql Server 2005 agent
I need to be able to schedule a job on the 10th of each
I am looking to use quartz to schedule emails, but I'm not sure which
I have code where I schedule a task using java.util.Timer . I was looking
I have a table which holds flight schedule data. Every schedule have an effective_from
I'm working with DotNetNuke's scheduler to schedule tasks and I'm looking to get the

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.