Adding UILocationNotification when the countdown reach 0

Hi, I have built an app the countdown for date for releasing games, I need to be able to notify users when the games are released via local notification.


I have done this but it seems not working

    UIApplication * app = [UIApplication sharedApplication];
    UILocalNotification * notification = [[UILocalNotification alloc]init];
    if (notification) {
        notification.fireDate = endingDate;
        notification.timeZone = [NSTimeZone defaultTimeZone];
        notification.alertBody = [NSString stringWithFormat:@"%@ has been released ",currentGame.gameName];
        [app scheduledLocalNotifications];
    }


here is my countdown method :


NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"YYYY-MM-dd"];
    NSDate *startingDate = [NSDate date];
    NSDate *endingDate = [dateFormatter dateFromString:[NSString stringWithFormat:@"%@", currentGame.gameDate]];
    NSUInteger unitFlags = NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitMinute|NSCalendarUnitSecond;
    NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSDateComponents *componentsDaysDiff = [gregorianCalendar components:unitFlags
                                                                fromDate:startingDate
                                                                  toDate:endingDate
                                                                 options:0];
   
    NSString *countdownText = [NSString stringWithFormat:@"%ld Months %ld Days %ld Minutes %ld Seconds", (long)componentsDaysDiff.month, (long)componentsDaysDiff.day, (long)componentsDaysDiff.minute, (long)componentsDaysDiff.second];
    if ((long)componentsDaysDiff.month <= 0 && (long)componentsDaysDiff.day <= 0 && (long)componentsDaysDiff.minute <= 0 && (long)componentsDaysDiff.second <= 0 ) {
        gamesCountdownLabel.text = @"Released";
    }else{
    gamesCountdownLabel.text = countdownText;
    }
    [gamesCountdownLabel.layer setCornerRadius:15.0f];
    [gamesCountdownLabel.layer setMasksToBounds:YES];
    [gamesCountdownLabel.layer setShadowRadius:5.0f];
    [gamesCountdownLabel.layer setShadowOffset:CGSizeMake(1.0f, 2.0f)];
  

There are some obvious problems with the code you posted [1] but these are probably not the reason why things are going wrong. It's hard to say what's going on with the information you've presented. First up, you said that it's not working but you didn't say what's going wrong or what steps you've taken to investigate the failure.


Share and Enjoy

--

Quinn "The Eskimo!"

Apple Developer Relations, Developer Technical Support, Core OS/Hardware


[1] See QA1480 "NSDateFormatter and Internet Dates".


<https://developer.apple.com/library/ios/#qa/qa1480/_index.html>

Adding UILocationNotification when the countdown reach 0
 
 
Q