每天重复的本地通知 - iOS

时间:2015-03-10 18:23:52

标签: ios background uilocalnotification

我在后台使用位置服务来每天更新我的应用。在后台,它解析XML并在18h设置本地通知,但仅当解析的数据不同时才会出现#34;没有警告"。但即使我不应该,我每天都会收到同样警报的通知。这就是我推送通知的方式。

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

}

0 个答案:

没有答案
相关问题