30 秒 - 1 分钟后检查用户是否仍在 CLRegion 内
Check if user is still within CLRegion after 30 seconds - 1 minute
我目前在用户进入区域时向他们发送本地通知。但是,我不想立即通知他们,因为有时他们会开车经过这些地区,不想一直收到通知。
因此,每当用户进入该区域时,都会调用 didEnterRegion。我想等待 30 秒(或可配置的时间),然后检查用户是否仍在该区域(我已经知道该怎么做),如果用户仍在该区域,则通知用户。
Android 有一种方法可以通过驻留 属性.
我知道我可以使用 dispatch_after(),但是当 phone 处于休眠状态(或应用程序已挂起)时,我无法重新获得主线程。
根据 Apple 的设计,phone 会在进入某个区域时自动唤醒。发生这种情况时,我想等待 30 秒,然后再次检查用户是否仍在原地。这是一个目前不起作用的代码片段:
// triggered when user enters monitored region.
func locationManager(manager: CLLocationManager, didEnterRegion region: CLRegion) {
// Wait 60 seconds and if user is still within region, try to send notification
delay(60){
self.locationManager.requestStateForRegion(region)
}
}
func locationManager(manager: CLLocationManager, didDetermineState state: CLRegionState, forRegion region: CLRegion) {
// only notify user if user is still within this region.
if state == CLRegionState.Inside{
if region is CLCircularRegion {
handleRegionEvent(region)
}
}
}
有一种方法可以做到这一点:
当应用程序收到用户进入某个区域的通知时,它应该在 30 秒后安排本地通知。您需要在此通知中设置标识符。
现在,如果没有任何反应,该通知将发送给用户。
会发生什么情况来阻止这种情况发生?
离开该区域的用户。
因此,当应用程序收到用户已离开某个区域的通知时,它应该查找具有某些已知标识符的计划通知,并删除它,因为它不再相关。
我目前在用户进入区域时向他们发送本地通知。但是,我不想立即通知他们,因为有时他们会开车经过这些地区,不想一直收到通知。
因此,每当用户进入该区域时,都会调用 didEnterRegion。我想等待 30 秒(或可配置的时间),然后检查用户是否仍在该区域(我已经知道该怎么做),如果用户仍在该区域,则通知用户。
Android 有一种方法可以通过驻留 属性.
我知道我可以使用 dispatch_after(),但是当 phone 处于休眠状态(或应用程序已挂起)时,我无法重新获得主线程。
根据 Apple 的设计,phone 会在进入某个区域时自动唤醒。发生这种情况时,我想等待 30 秒,然后再次检查用户是否仍在原地。这是一个目前不起作用的代码片段:
// triggered when user enters monitored region.
func locationManager(manager: CLLocationManager, didEnterRegion region: CLRegion) {
// Wait 60 seconds and if user is still within region, try to send notification
delay(60){
self.locationManager.requestStateForRegion(region)
}
}
func locationManager(manager: CLLocationManager, didDetermineState state: CLRegionState, forRegion region: CLRegion) {
// only notify user if user is still within this region.
if state == CLRegionState.Inside{
if region is CLCircularRegion {
handleRegionEvent(region)
}
}
}
有一种方法可以做到这一点: 当应用程序收到用户进入某个区域的通知时,它应该在 30 秒后安排本地通知。您需要在此通知中设置标识符。 现在,如果没有任何反应,该通知将发送给用户。
会发生什么情况来阻止这种情况发生? 离开该区域的用户。
因此,当应用程序收到用户已离开某个区域的通知时,它应该查找具有某些已知标识符的计划通知,并删除它,因为它不再相关。