Reputation: 1174
i want to show local notification on every saturday like this,
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat=@"EEEE";
NSString *dayString = [[dateFormatter stringFromDate:[NSDate date]] capitalizedString];
NSLog(@"day: %@", dayString);
if([dayString isEqualToString:@"Saturday"])
{
NSLog(@"Success");
[self PushNotification];
}
-(void)PushNotification
{
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.alertTitle = @"Test";
localNotification.alertBody =@"test of notification";
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *componentsForFireDate = [calendar components:(NSCalendarUnitYear | NSCalendarUnitWeekOfMonth | NSCalendarUnitHour | NSCalendarUnitMinute| NSCalendarUnitSecond | NSCalendarUnitWeekday) fromDate: [NSDate date]];
[componentsForFireDate setWeekday: 7]; //for fixing Saturday
[componentsForFireDate setHour: 17]; //for fixing 5PM hour
[componentsForFireDate setMinute:0];
[componentsForFireDate setSecond:0];
localNotification.repeatInterval = NSCalendarUnitWeekOfMonth;
}
but my local notification is display in every minit then how can i display notification on every Saturday of the week. thanks.
Upvotes: 0
Views: 54
Reputation: 2446
Try to declare fireData
property in localNotification
and schedule your notification
localNotification.fireDate = componentsForFireDate.date;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
Hope this help
Upvotes: 0