evenArray[]
包含本地通知列表这是通知我将比较我的通知所需的参数" 144 = mas" 144是唯一的,索引也是唯一的
"<UIConcreteLocalNotification: 0x118b08c0>{fire date = Monday, September 29, 2014 at 6:12:00 PM India Standard Time, time zone = Asia/Kolkata (GMT+5:30) offset 19800, repeat interval = NSWeekCalendarUnit, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = Monday, September 29, 2014 at 6:12:00 PM India Standard Time, user info = {\n 144 = mas;\n index = 63;\n userid = \"821e25e7-d76c-4328-bbba-8e367dc70c04\";\n}}",
"<UIConcreteLocalNotification: 0x118b0cc0>{fire date = Monday, September 29, 2014 at 6:12:00 PM India Standard Time, time zone = Asia/Kolkata (GMT+5:30) offset 19800, repeat interval = NSWeekCalendarUnit, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = Monday, September 29, 2014 at 6:12:00 PM India Standard Time, user info = {\n 153 = mbg;\n index = 64;\n userid = \"821e25e7-d76c-4328-bbba-8e367dc70c04\";\n}}"
)
答案 0 :(得分:2)
您可以使用 [[UIApplication sharedApplication] cancelLocalNotification:(UILocalNotification *)] 或 [[UIApplication sharedApplication] cancelAllLocalNotifications] 清除之前的通知。
您还在 [[UIApplication sharedApplication] scheduledLocalNotifications] 中安排了NSArray预定通知。
使用这些方法,您应该能够管理通知。
答案 1 :(得分:1)
在您编辑记录时,在阅读您的问题之后我会理解您在添加编辑时间的时间时添加的相同通知。如果是正确的,则需要在编辑记录时删除以前的通知。如果您有多个记录,并且对于该记录您有多个通知,则需要为该通知提供一些唯一ID,以便您可以轻松识别需要删除的通知。
我也遇到了同样的问题,所以我在userInfo
字典中存储了一个唯一值作为整数,每当我添加或编辑通知时,首先我检查它,如果已经添加,则删除它并添加另一个因为我的情况我想根据编辑的记录通知。
我正在使用的代码在这里,可能会对您有所帮助。
-(void )scheduleNotification:(NSString *)remainderText :(BOOL )isRepeat :(NSDate *)fireDate :(NSString *)notificationId{
NSDictionary *dict=[[NSMutableDictionary alloc]init];
[dict setValue:@"NotificationID" forKeyPath:notificationId];
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.alertBody=@"Your Msg";
localNotification.timeZone=[NSTimeZone localTimeZone];
localNotification.userInfo = dict;
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
localNotification.fireDate=fireDate;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
-(void) deleteNotification:(NSString *)curentNotificationId
{
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 *uid=[NSString stringWithFormat:@"%@",[userInfoCurrent valueForKey:@"NotificationID"]];
if ([uid isEqualToString:curentNotificationId])
{
//Cancelling local notification
[app cancelLocalNotification:oneEvent];
}
}
}
检查它..在你想要的日程安排通知方法中写下其他东西,并记住传递给scheduleNotification方法的notificationID应该是唯一的
答案 2 :(得分:-1)
如果您要删除
下面的特定通知使用用于UIApplication.sharedApplication()。scheduledLocalNotifications
中的通知{
UIApplication.sharedApplication()。cancelLocalNotification(通知)
}
或强>
如果您要删除下面的所有通知使用
[[UIApplication sharedApplication] cancelAllLocalNotifications]。