这是didEnterRegion
函数的代码。问题是通知在进入和退出时触发。只有当用户进入该位置时,我该怎么做才能触发通知?
func locationManager(manager: CLLocationManager!, didEnterRegion region: CLRegion!) {
var localNotification:UILocalNotification = UILocalNotification()
localNotification.alertBody = "you've entered rohini sector -8"
localNotification.region = region
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
NSLog("Entering region")
}
答案 0 :(得分:1)
You don't need to specify the region in the local notification. You already know that the device is inside the region, because you had a call to didEnterRegion
- specifying the region on the notification is redundant - You can simply post the notification without the region specified.
答案 1 :(得分:1)
您没有指定要监控进入或退出该区域。创建区域时,请设置notifyOnExit或notifyOnEntry。如果你只想要退出,那么将该值设为true,另一个为false ...或者如果只有entry ..执行相反的操作
///// snipped taken from ray wenderlichs code...
// 1
let region = CLCircularRegion(center: geotification.coordinate,
radius: geotification.radius, identifier: geotification.identifier)
// 2
region.notifyOnEntry = false
region.notifyOnExit = true