EKReminder 根据时间提醒 和地理围栏
根据此网址一步一步学习,可以基本了解。
-(BOOL)TimeReminder:(NSString *)title date:(NSDate *)date
{ BOOL result=YES;
if (self.eventStore==nil) { self.eventStore=[[EKEventStore alloc] init]; [self.eventStore requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted,NSError *error){ if (!granted) { NSLog(@"access to store not granted"); } }]; } EKReminder *reminder=[EKReminder reminderWithEventStore:self.eventStore]; reminder.calendar=[self.eventStore defaultCalendarForNewReminders]; reminder.title=title; EKAlarm *alarm=[EKAlarm alarmWithAbsoluteDate:date]; [reminder addAlarm:alarm]; NSError *error=nil; [self.eventStore saveReminder:reminder commit:YES error:&error]; if (error) { NSLog(@"error=%@",error); result=NO; } return result; }
/* 地理围栏 参数:title reminder 标题 radius 定位精度 proximity enum { EKAlarmProximityNone, EKAlarmProximityEnter, EKAlarmProximityLeave }; typedef NSInteger EKAlarmProximity; 提醒类型,是离开时提醒,还是进入提醒 */
-(BOOL)LocationReminder:(NSString *)title location:(CLLocation *)location radius:(double)radius promixity:(EKAlarmProximity)proximity { BOOL result=YES; if (self.eventStore==nil) { self.eventStore=[[EKEventStore alloc] init]; [self.eventStore requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted,NSError *error){ if (!granted) { NSLog(@"access to store not granted"); } }]; } self.locationManager = [[CLLocationManager alloc] init]; self.locationManager .distanceFilter=kCLDistanceFilterNone; self.locationManager .desiredAccuracy=kCLLocationAccuracyBest; EKReminder *locationReminder=[EKReminder reminderWithEventStore:self.eventStore]; locationReminder.title=title; locationReminder.calendar=[self.eventStore defaultCalendarForNewReminders]; CLGeocoder *geocoder=[[CLGeocoder alloc] init]; [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) { for (CLPlacemark *place in placemarks){ self.destination=place.name; } }]; NSLog(@"name%@",self.destination); EKStructuredLocation *structLocation=[EKStructuredLocation locationWithTitle:self.destination]; structLocation.geoLocation=location; structLocation.radius=radius; EKAlarm *alarm=[[EKAlarm alloc] init]; alarm.structuredLocation=structLocation; alarm.proximity=proximity; [locationReminder addAlarm:alarm]; NSError *error=nil; [self.eventStore saveReminder:locationReminder commit:YES error:&error]; if (error) { NSLog(@"location reminder is error %@",error); result=NO; }
return result; }