Android geofences that never fired: a permission promise that lied, and a cache that outlived the OS
A reminder tied to a place is the one feature where you cannot poll.
重點摘要
A permission promise resolved before the user answered, so the JS flow skipped the background-location step.
A cached “already armed” set in AsyncStorage survived reboot and app updates, preventing re-registration.
Boot, package-replaced, and periodic WorkManager jobs re-arm geofences; a larger radius fixed imprecise “home” locations.
This article traces three separate reasons Android geofences appeared to “never fire.” First, the permission bridge resolved too early: it told JavaScript the request had been denied before the user answered the system dialog, so the background-location step was never requested. Second, the app cached the last requested geofence set in AsyncStorage and incorrectly treated that cache as the source of truth, skipping native re-registration even after reboot or app updates had cleared Play services’ region state. The fix was to always re-arm unless both current and next sets are empty. Third, some “home” reminders missed because the geocoded anchor was too precise; a minimum radius for colloquial places addressed that. The post closes by noting that the repair logic is idempotent and cheap, so it should not be optimized away.
从未触发的 Android 地理围栏:一个撒谎的权限承诺,以及一个比操作系统更长寿的缓存
绑定地点的提醒,是唯一不能靠轮询解决的功能。
重點摘要
权限流程在用户尚未响应前就返回,导致 JS 跳过了后台定位步骤。
AsyncStorage 中的缓存被误当成真实状态,重启或更新后反而阻止重新注册。
开机、包更新和定期任务会重置围栏;“home”等口语地点则需要更大的半径。
这篇文章解释了 Android 地理围栏迟迟不触发的三个原因。首先是原生权限桥接过早返回:系统对话框还在等待用户选择时,JS 就收到了“denied”,于是后台定位权限的后续步骤根本没有执行。其次,应用把最后一次下发的围栏集合缓存到 AsyncStorage,却把这个缓存误当成真实状态;在重启或应用更新后,Play services 里的围栏已被清空,程序却因为缓存未变而跳过重新注册。修复方法是只有在新旧集合都为空时才跳过原生调用。最后,像“home”这样的口语地点因地理编码不够精确,需要提高最小半径。
Android 地理圍欄從未觸發:一個說謊的權限承諾,以及比作業系統更長命的快取
綁定地點的提醒,是唯一不能靠輪詢解決的功能。
重點摘要
權限流程在使用者尚未回覆前就回傳結果,導致 JS 跳過背景定位步驟。
AsyncStorage 的快取被誤當成真實狀態,重開機或更新後反而阻止重新註冊。
開機、套件更新與週期性工作會重設圍欄;「home」等口語地點則需要更大的半徑。
這篇文章說明 Android 地理圍欄遲遲不觸發的三個原因。首先是原生權限橋接太早回應,系統對話框還在等待使用者選擇時,JS 就已收到「denied」,因此背景定位權限的後續步驟根本沒走到。其次,App 把最後一次送出的圍欄清單存進 AsyncStorage,卻把這個快取誤認為真實狀態;在重開機或 App 更新後,Play services 內的圍欄已被清空,程式卻因快取相同而跳過重新註冊。修正方式是只在新舊集合都為空時才略過原生呼叫。最後,像「home」這類口語地點因地理編碼落點不準,需要加大最小半徑。