gpt4 book ai didi

ios - 30 秒 - 1 分钟后检查用户是否仍在 CLRegion 内

转载 作者:行者123 更新时间:2023-11-29 00:59:45 27 4
gpt4 key购买 nike

我目前在用户进入区域时向他们发送本地通知。但是,我不想立即通知他们,因为有时他们会开车经过这些区域并且不想一直收到有关这些区域的通知。

因此,每当用户进入该区域时,都会调用 didEnterRegion。我想等待 30 秒(或可配置的时间),然后检查用户是否仍在该区域(我已经知道该怎么做),如果用户仍在该区域,则通知用户。

Android 有一种使用 dwell 属性的方法。

我知道我可以使用 dispatch_after(),但是当手机处于休眠状态(或应用程序挂起)时我无法获得主线程。

根据 Apple 的设计,当进入某个区域时,手机会自动唤醒。发生这种情况时,我想等待 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 秒后安排本地通知。您需要在此通知中设置标识符。现在,如果没有任何反应,该通知将发送给用户。

什么情况会阻止这种情况发生?用户离开该区域。

因此,当应用收到用户已离开某个区域的通知时,它应该查找具有某些已知标识符的预定通知,并在它不再相关时将其删除。

关于ios - 30 秒 - 1 分钟后检查用户是否仍在 CLRegion 内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37147900/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com