gpt4 book ai didi

ios - 本地通知每天和每月重复

转载 作者:行者123 更新时间:2023-11-28 18:33:46 28 4
gpt4 key购买 nike

我有本地通知。像这样 ;

NSNumberFormatter *faturaSonOdemeGunuFormatter = [[NSNumberFormatter alloc] init];
[faturaSonOdemeGunuFormatter setNumberStyle:NSNumberFormatterNoStyle];
NSNumber *faturaSonOdemeGunuNumber = [faturaSonOdemeGunuFormatter numberFromString:_txtFaturaGunu.text];

NSDate *currentDate = [NSDate date];
NSCalendar * calendar = [NSCalendar currentCalendar];
[calendar setTimeZone:[NSTimeZone systemTimeZone]];
NSDateComponents* components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:currentDate];

[components setTimeZone:[NSTimeZone systemTimeZone]];
[components setHour:12];
[components setMinute:40];
[components setDay: faturaSonOdemeGunuNumber.integerValue -3];

NSDate *test = [calendar dateFromComponents:components];


// Schedule the notification
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = test;
localNotification.alertBody = [NSString stringWithFormat:@"%@ Faturanıza 3 gün kaldı.",_txtFaturaAdi.text];
localNotification.alertAction = @"Faturayı göster";
localNotification.timeZone = [NSTimeZone systemTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

// Request to reload table view data
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:self];

此代码不会重复。我想在 faturaSonOdemeGunuNumber integerValue 日每个月重复一次本地通知。应该从 sonOdemeGunuNumber -3 开始(例如用户写 17。它应该从 14 开始)并且应该在每个月发出通知直到 faturaSonOdemeGunuNumber 的一天。我的意思是它应该继续每天通知用户直到选定的日期。我该怎么做?

谢谢!

最佳答案

添加这个:

localNotification.repeatInterval = kCFCalendarUnitMonth; //For monthly repeats
localNotification.repeatInterval = kCFCalendarUnitDay; //For daily repeats

关于ios - 本地通知每天和每月重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23195298/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com