当用户进入特定区域提供的ios时如何获得本地通知

我正在从事这样的项目,应用程序执行以下操作:

1.获取用户当前的位置。 2.当用户进入或附近我提供的特定位置获取本地通知。

我所做的是:

我已经下载了区域示例代码(苹果提供)来找出我的当前位置使用IOS corelocation框架。它工作正常。下面的代码:

//根据地图视图的中心创build一个新的区域。

CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(regionsMapView.centerCoordinate.latitude, regionsMapView.centerCoordinate.longitude); CLRegion *newRegion = [[CLRegion alloc] initCircularRegionWithCenter:coord radius:2.0 identifier:[NSString stringWithFormat:@"%f, %f", regionsMapView.centerCoordinate.latitude, regionsMapView.centerCoordinate.longitude]]; 

现在我的问题是如何添加经纬度的特定区域来获得通知?

帮助是高度赞赏。任何人都知道任何例子或教程。

探索iOS Core Location框架提供的基于位置的服务。

这里有一些很好的教程。 它可以帮助你

  • 采用核心位置的地理围栏
  • iOS上的地理围栏
  • iOS Geofencing API教程使用Core Location Framework

SetSDK应该可以使这个超级简单, https ://cocoapods.org/pods/SetSDK。 它允许您设置用户到达和离开位置的通知。 它目前正在学习这些位置,但即将发布的版本包括任意位置订阅。 你的应用程序将收到通知,你可以从那里执行你想要的任何处理程序。 它看起来像这样,

 SetSDK.instance.onArrival(to: .any) { newArrival in /* Compare the new location with the one of interest (50m) */ if newArrival.location.distance(from: placeOfInterest) < 50 { /* do your things here */ } } 

1.获取用户当前的位置。

我在博客和Github上发布了冗长的post和示例代码,介绍如何获取iOS 7的位置信息。

  • 背景位置更新编程的iOS 7

  • Github项目:iOS 7的背景位置更新编程

2.当用户进入或附近我提供的特定位置获取本地通知。

您将不得不使用startMonitoringForRegion来监视您创build的区域。

 CLLocationCoordinate2D regionCentre = CLLocationCoordinate2DMake(latitude, longitude); CLCircularRegion *region= [[CLCircularRegion alloc] initWithCenter:regionCentre radius:radius identifier:@"Name"]; [locationManager startMonitoringForRegion:region]; 

从locationManager委托中,您将在进入该区域时收到通知。

 -(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region{ NSString* message = [NSString stringWithFormat:@"Message"; UIApplicationState state = [[UIApplication sharedApplication] applicationState]; if (state == UIApplicationStateBackground || state == UIApplicationStateInactive) { UILocalNotification *notification = [[UILocalNotification alloc] init]; notification.fireDate = [NSDate date]; NSTimeZone* timezone = [NSTimeZone defaultTimeZone]; notification.timeZone = timezone; notification.alertBody = message; notification.alertAction = @"Show"; notification.soundName = UILocalNotificationDefaultSoundName; [[UIApplication sharedApplication] scheduleLocalNotification:notification]; } }