Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
每天重复的本地通知-iOS_Ios_Background_Uilocalnotification - Fatal编程技术网

每天重复的本地通知-iOS

每天重复的本地通知-iOS,ios,background,uilocalnotification,Ios,Background,Uilocalnotification,我每天都在后台使用定位服务更新我的应用程序。在后台,它解析XML并将本地通知设置为18小时,但仅当解析的数据不同时,才显示“无警告”。但我每天都收到同样的通知,即使我不应该这样做。这就是我推送通知的方式 If(![self.city isEqualToString:@"No warning"]){ // We only need 1 notification [[UIApplication sharedApplication] cancelAllLocalNotifications];

我每天都在后台使用定位服务更新我的应用程序。在后台,它解析XML并将本地通知设置为18小时,但仅当解析的数据不同时,才显示“无警告”。但我每天都收到同样的通知,即使我不应该这样做。这就是我推送通知的方式

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];

}

你准备好了吗?城市?我已经解决了这个问题解决方案是什么?