【发布时间】:2019-01-12 13:50:23
【问题描述】:
我在应用程序上工作,我在该应用程序上监控地点并在进入区域时发送本地通知。
我将这些地方保存在领域数据库中并检查区域。
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print("Updated user's location")
shouldSetRegion = false
updateLocation()
print((locations.last?.coordinate.longitude)!)
if !(realm.objects(Coupon.self).isEmpty) {
for item in realm.objects(Coupon.self) {
let lat: CLLocationDegrees = CLLocationDegrees(item["lat"] as! String)!
let lng: CLLocationDegrees = CLLocationDegrees(item["lng"] as! String)!
center = CLLocationCoordinate2D(latitude: lat, longitude: lng)
region = CLCircularRegion(center: center, radius: 5000, identifier: "startPosition")
print(region)
manager.startMonitoring(for: region)
}
manager.startUpdatingLocation()
}
}
我使用此代码,他只在用户输入数据库中的最后一个区域时收到通知,尽管数据库包含多个地方。
func updateLocation(){
shouldSetRegion = true
locationManager.startUpdatingLocation()
}
所以关于监控地点和发送本地通知的任何帮助。
@objc func didEnterRegion() {
print("da5alt hena")
for item in realm.objects(Coupon.self){
let title = item["name"] as! String
let body = item["desc"] as! String
let id = item["BranchId"] as! String
VKNotificationService.sharedInstance.locationRequest(title, body, for: id)
}
}
【问题讨论】:
标签: ios swift cllocationmanager