这是我的localNotification代码。
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:13];
[components setMinute:11];
[components setDay: sonOdemeGunuNumber.integerValue -3];
NSDate *test = [calendar dateFromComponents:components];
// Schedule the notification
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = test;
localNotification.alertBody = [NSString stringWithFormat:@"%@ 3 days left.",_txtBankaAdi.text];
localNotification.alertAction = @"Show item";
localNotification.timeZone = [NSTimeZone systemTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
localNotification.repeatInterval = kCFCalendarUnitDay;
localNotification.repeatInterval = kCFCalendarUnitMonth;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
sonOdemeGunuNumber是ToDoItem警报日(例如-3的当前天数)。
if(sonOdemeGunuNumber.integerValue == currentDay.integerValue){
localNotification.repeatInterval = nil; }
我想提前3天通知用户,它应该继续保持警报,直到currentDay = sonOdemeGunuNumber。
1-如果我写这个if-else语句它会起作用吗?
2-如果用户在我的TableView中删除localNotification项目,在这种情况下项目是银行账户? 银行账户localNotification会自动删除吗?
谢谢! 祝每个人都过得愉快......
答案 0 :(得分:0)
我找到了解决方法,如果用户删除了tableview中的项目我取消了已删除的项目的localNotification ..
首先,使用userInfo将ID发送到LocalNotification Center。
localNotification.userInfo = [NSDictionary dictionaryWithObjectsAndKeys:_txtItemName.text,@"delThisNot", nil];
其次去编辑你的tableView方法。
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{ if(editingStyle == UITableViewCellEditingStyleDelete){
UIApplication *app = [UIApplication sharedApplication];
NSArray *eventArray = [app scheduledLocalNotifications];
for (int i=0; i<[eventArray count]; i++)
{
UILocalNotification* oneEvent = [eventArray objectAtIndex:i];
NSDictionary *userInfoCurrent = oneEvent.userInfo;
NSString *adi = [[self.fetchedResultsController objectAtIndexPath:indexPath]valueForKey:@"odemeAdi"];
NSString *uid=[NSString stringWithFormat:@"%@",[userInfoCurrent valueForKey:@"delThisNot"]];
if ([uid isEqualToString:adi])
{
//Cancelling local notification
[app cancelLocalNotification:oneEvent];
break;
}
}
}
adi =正在删除项目。 uid =您的商品ID(这是您的txtItemName.text)
if ([uid isEqualToString:adi])
{
//Cancelling local notification
[app cancelLocalNotification:oneEvent];
break;
}
如果用户想要删除项目名称(adi)== uid(txtItemName.Text)
取消此通知。
对不起我的语法我只是想帮助其他人,我希望你们能理解我:D
感谢。