只要位置靠近,通知就会激活,但它只在后台工作。即使触发事件发生在前台和后台。
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
//implement local notification:
UIApplication *app = [UIApplication sharedApplication];
UILocalNotification *notification = [[UILocalNotification alloc] init];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
if (notification == nil)
return;
notification.fireDate = [NSDate date];
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.alertBody = [selectedTask discription];
notification.alertAction = [selectedTask taskName];
notification.soundName = UILocalNotificationDefaultSoundName;
notification.applicationIconBadgeNumber = 1;
[app presentLocalNotificationNow:notification];
localNotification = nil;
}