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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:12:02+00:00 2026-05-29T07:12:02+00:00

I have a view controller which contains a field for user to enter date

  • 0

I have a view controller which contains a field for user to enter date value.In contrast I have a field called “Remind Before Days” for the user to select when the notification should fire.If the remind before day is same day,then notification is set to fire on the date,but when the remind day is before 1 day,then notification should fire before one day the date set(specified).For this I have written a method called -(void)setNotification and here is the implementation code:

- (void)setNotification
{
    //Set notification after confirmation of saved data

    Class cls = NSClassFromString(@"UILocalNotification");
    UILocalNotification *notif = [[cls alloc] init];

    if (cls != nil) 
    {
        textField = [self.fields objectAtIndex:3];

        if (textField.text == @"Same Day") 
        {
            notif.fireDate = [datePicker date];
            notif.timeZone = [NSTimeZone defaultTimeZone];
        }
        else if(textField.text == @"1 Day")
        {
            NSDate *now = [datePicker date];

            // set up date components
            NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:now];
            [components setDay:-1];

            // create a calendar to form date
            NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
            NSDate *newDate2 = [gregorian dateByAddingComponents:components toDate:now options:0];

            notif.fireDate = newDate2;
            notif.timeZone = [NSTimeZone defaultTimeZone];
        }
        notif.timeZone = [NSTimeZone defaultTimeZone];
        notif.alertBody = textView.text;
        notif.alertAction = @"View";
        notif.soundName = @"lazy_afternoon.mp3";
        notif.applicationIconBadgeNumber = 1;
        textField = [self.fields objectAtIndex:1];
        NSDictionary *userDict = [NSDictionary dictionaryWithObject:self.textField.text forKey:kReminder];
        notif.userInfo = userDict;
        [[UIApplication sharedApplication] scheduleLocalNotification:notif];
        [notif release];
    }
}

Now as we are all aware that when the notification gets fired,the user clicks view.Then we show an alert,the implementation code is written in appDelegate.Here it is:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{    

    // For The Purpose Of Notification.
    Class cls = NSClassFromString(@"UILocalNotification");
    if (cls) 
    {
        UILocalNotification *notification = [launchOptions objectForKey:
                                             UIApplicationLaunchOptionsLocalNotificationKey];

        if (notification) 
        {
        NSString *reminderText = [notification.userInfo objectForKey:kReminder];
        [self.viewController showReminder:reminderText];
        }
    }

    application.applicationIconBadgeNumber = 0;
}

Now after local notification is received,we do the following i.e.:

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification 
{
    application.applicationIconBadgeNumber = 0;
    NSString *reminderText = [notification.userInfo objectForKey:kReminder];
    [self.viewController showReminder:reminderText];
}

Now I have set the -(void)setNotification action to right navigation right bar button item titled “Save” as follows:

-(IBAction)save:(id)sender
{
[self setNotification];
}

When I don’t specify any condition for fire date i.e. simply assign as :

notif.fireDate = [datePicker date]; everything’s fine with notification(no issues).

But when I do as the above i.e. condition for fire date,then the notification is not getting fired.Instead the alert is getting fired when I click save.Also when I quit the simulator,I could see some thread problem.I don’t understand what’s wrong with the code (implementation).I have gone through several links,also the apple documentation of UILocalNotification.Couldn’t find out any property or method to set fire Date according to conditions.

I found out a method “repeatTimeInterval” which is relavant and applicable when a notification must be repeated weekly,yearly etc..which doesn’t suit the requirement that the “date to be fired is this when the remind days in textField is this”

Can any one please guide me right,

Thanks all 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-05-29T07:12:03+00:00Added an answer on May 29, 2026 at 7:12 am

    I believe if you check this link out you will find out. But from what I have seen the code you have provide is from this site anyway.

    http://useyourloaf.com/blog/2010/7/31/adding-local-notifications-with-ios-4.html

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

Sidebar

Related Questions

So, i have a view controller which contains just a scroll view. In viewDidLoad,
I have a class called Chair. I have a view controller that contains an
I have a root view controller which contains an outlet for my login view
I have a UIScrollView which contains a view controller which contains a couple of
I have 2 view controller pages.Add Reminder page which contains save button as right
I have a view controller which contains a scroll view. Inside the scroll view
I have a view controller which contains a table view, and which is wrapped
I have a table view controller which doesn't let me manually scroll to the
I have a navigation controller which also has a table view. I want to
In my IB I have a navigation controller which has in it a view

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.