每天重复的本地通知-iOS
我每天都在后台使用定位服务更新我的应用程序。在后台,它解析XML并将本地通知设置为18小时,但仅当解析的数据不同时,才显示“无警告”。但我每天都收到同样的通知,即使我不应该这样做。这就是我推送通知的方式每天重复的本地通知-iOS,ios,background,uilocalnotification,Ios,Background,Uilocalnotification,我每天都在后台使用定位服务更新我的应用程序。在后台,它解析XML并将本地通知设置为18小时,但仅当解析的数据不同时,才显示“无警告”。但我每天都收到同样的通知,即使我不应该这样做。这就是我推送通知的方式 If(![self.city isEqualToString:@"No warning"]){ // We only need 1 notification [[UIApplication sharedApplication] cancelAllLocalNotifications];
If(![self.city isEqualToString:@"No warning"]){
// We only need 1 notification
[[UIApplication sharedApplication] cancelAllLocalNotifications];
NSCalendar *gregCalendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *dateComponents = [gregCalendar components: NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:[NSDate date]];
[dateComponents setYear:[dateComponents year]];
[dateComponents setMonth:[dateComponents month]];
[dateComponents setDay:[dateComponents day]];
[dateComponents setHour:18];
[dateComponents setMinute:0];
UIDatePicker *dd = [[UIDatePicker alloc]init];
[dd setDate:[gregCalendar dateFromComponents:dateComponents]];
UILocalNotification *notification = [[UILocalNotification alloc]init];
notification.alertBody = [NSString stringWithFormat:@"%@ %@",self.date,self.city];
notification.soundName = UILocalNotificationDefaultSoundName;
notification.repeatInterval = 0;
[notification setFireDate:dd.date];
[notification setTimeZone:[NSTimeZone defaultTimeZone]];
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
你准备好了吗?城市?我已经解决了这个问题解决方案是什么?