Search code examples
iosobjective-cuilocalnotification

Issue with local notification


i am trying to get notification when date of array become same as current date this code is i am using for this task

NSDateFormatter *Form = [[NSDateFormatter alloc] init];
    [Form setDateFormat:@"dd/MM/yyyy"];

    UILocalNotification *notification = [[UILocalNotification alloc] init];
    for (int i=0;i<_convertedBdates.count;i++)
    {
        NSDate *date =[Form dateFromString:[_convertedBdates objectAtIndex:i ]];
        NSLog(@"date%@",date);

    if(notification)
        {
            notification.fireDate = date;
            notification.timeZone = [NSTimeZone defaultTimeZone];
            notification.alertBody = @"New ";
            notification.alertAction = @"View";

            notification.soundName = UILocalNotificationDefaultSoundName;
            notification.applicationIconBadgeNumber = 1;
            [[UIApplication sharedApplication] scheduleLocalNotification:notification];
        }
    }

suggest me what i am doing wrong


Solution

  • have you put this code in your app delegate?

     - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
    {
        NSLog(@"Notification Received, %@, set for date %@", notification.alertBody, notification.fireDate);
    }
    

    if problem persist then i am here :)