仅当用户进入指定区域时触发 localNotification

trigger localNotification only when user enters a specified region

这是我的 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")
    }

您无需在本地通知中指定地区。您已经知道该设备在该区域内,因为您调用了 didEnterRegion - 在通知中指定区域是多余的 - 您可以简单地 post 不指定区域的通知。

您没有指定是否要监控进入或离开该区域。创建区域时,您设置 notifyOnExit 或 notifyOnEntry 。如果您只想退出,那么将那个值设置为真,另一个设置为假...或者如果只是进入...则相反

///// 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