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)];