Wie Benachrichtigung jeden Monat Benachrichtigung.So melden Sie eine Benachrichtigung an jedem Monat Ende Tag
-(void)applicationDidEnterBackground:(UIApplication *)application {
NSDateFormatter *format = [[NSDateFormatter alloc] init];
format.dateFormat = @"dd-MM-yyyy";
NSComparisonResult result = [[format stringFromDate:[NSDate new]] compare:[format stringFromDate:[self lastDayOfMonthOfDate:[NSDate date]]]];
if (result == NSOrderedSame){
if (![USERDEFAULTS boolForKey:@"IS_MONTH"]) {
[self getNotifiedForEveryMonth:nil];
}}
else{
[USERDEFAULTS setBool:NO forKey:@"IS_MONTH"];
}
}
// getNotifiedForEveryMonth
-(void)getNotifiedForEveryMonth:(id)userinfo{
// Schedule the notification
[USERDEFAULTS setBool:YES forKey:@"IS_MONTH"];
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate date];
localNotification.alertBody = @"Every Month Notificiation";
localNotification.alertAction = @"Show me the item";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
}
-(NSDate*)lastDayOfMonthOfDate:(NSDate *)date
{
// NSGregorianCalendar
NSInteger dayCount = [self numberOfDaysInMonthCountForDate:date];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
[calendar setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
NSDateComponents *comp = [calendar components:
NSCalendarUnitYear |
NSCalendarUnitMonth |
NSCalendarUnitDay fromDate:date];
[comp setDay:dayCount];
return [calendar dateFromComponents:comp];
}
-(NSInteger)numberOfDaysInMonthCountForDate:(NSDate *)date
{
NSCalendar *calendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
[calendar setTimeZone:[NSTimeZone timeZoneWithName:TIME_ABSOLUTE]];
NSRange dayRange = [calendar rangeOfUnit:NSCalendarUnitDay
inUnit:NSCalendarUnitMonth
forDate:date];
return dayRange.length;
}
Der obige Code mit i versuchen, die Mitteilung zu benachrichtigen. Es erhalten Benachrichtigung jeden Monat Ende Tag,
Wenn Benutzer die Benachrichtigung schließen und dann im nächsten Monat kommt, benachrichtigt die Benachrichtigung nicht.
Nach der Installation der Anwendung, wie der Benutzer sehr Monat Ende Tag eine Benachrichtigung Nachricht zu benachrichtigen.
Ihre Eingaben sind willkommen.
Also im Grunde Sie möchten am letzten Tag eines jeden Monats eine Benachrichtigung versenden? – Harsh
@Harsh ja sein für jeden Monat zu Ende. – KkMIW
Warum haben Sie eine Benachrichtigung gesendet, wenn Ihre Anwendung in den Hintergrund tritt? – Harsh