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

标签 ios cllocationmanager uilocalnotification

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

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

我所做的是:

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

//基于 map View 的中心创建一个新区域。

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

现在,我的问题是如何添加具有纬度和经度的特定区域以获得通知?

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

最佳答案

SetSDK 应该有助于让这变得 super 简单,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 */
    }
}

关于ios - 用户进入特定区域时如何获取本地通知提供的 ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23535653/

相关文章:

ios - 是否可以将Unity与UIKit混合使用?

ios - 在后台运行的 GPS 应用程序

iphone - UILocalNotification 触发日期问题

iphone - 调用 UILocalNotification cancelAllLocalNotifications 是仅取消调用它的应用程序的通知还是所有通知?

ios - XCode 9 在项目之间切换

iphone - 在 Objective-c 中画圆

ios - 在表格单元格上播放视频

swift - LocationManager didEnterRegion 未调用(再次)

ios - 替换 CLLocationManager 的 "purpose"属性

ios - iOS 的 UILocalNotification 中不显示操作和类别