Help with local notifications

Discussion in 'iOS Programming' started by kalebhoot, Jul 5, 2012.

  1. kalebhoot macrumors newbie

    Joined:
    Jul 26, 2011
    #1
    hey guys,

    I am trying to set a up time based notification but seem to have problem scheduling notifications that are in the same day (or close enough proximity) and older dates. Here's some of the code I'm working with:

    This is where I create a reminder for a task with a date:

    Code:
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
        [dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        [dateFormatter setTimeZone:[NSTimeZone localTimeZone]];    
        NSDate *reminderDate = [dateFormatter dateFromString:@"2012-07-05 23:47:25"];
    and I have a function that adds it to the list of local notifications:




    Code:
    - (IBAction)addReminder:(id)sender 
    {  
        UILocalNotification *notification = [[UILocalNotification alloc] init];
            
        if(notification)
        {
            notification.fireDate = self.task.reminderDate;
            notification.timeZone = [NSTimeZone localTimeZone];
            notification.repeatInterval = 0;
            notification.alertBody = @"Test";
            [[UIApplication sharedApplication] scheduleLocalNotification:notification];
        }
    }

    However, if it doesn't notify me if I try to make the dates close (by like 10 secs) so I can test it. When I check the count of the scheduledlocalnotifications, it shows up as 0. I'm not sure what the problem is and I can't seem to find a solution. The only time it comes up as a problem is when the dates are close to each other or on the same day.

    Logically, this doesn't make sense to me that this might be causing the notification to be not added as I can have tasks that I want myself to be reminded of within minutes or even hours. Any help would be appreciated. Thanks!
     
  2. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #2
    As I understand it, your app is trying to send a reminder to it self. I found the following in the docs and perhaps it applies here. It certainly will if your app is on the screen.

    "If the application is foremost and visible when the system delivers the notification, no alert is shown, no icon is badged, and no sound is played. However, the application:didReceiveLocalNotification: is called if the application delegate implements it. The UILocalNotification instance is passed into this method, and the delegate can check its properties or access any custom data from the userInfo dictionary."

    Also, your code isn't your real working code. That hard coded date in the past tells me that much. Place in actual code you are working with. It allows the sharp eye to zero in on real issues.
     

Share This Page