一个电池效率高且注重隐私的小型框架,用于监测用户位置,在用户开始移动时触发回调,并监测用户是否接近指定区域。
依赖于多种技术的组合,例如:
GeoMonitor 需要 iOS 14+
self.monitor = GeoMonitor {
// Fetch the latest regions; also called when entering one.
// Make sure `region.identifier` is stable.
let regions = await ...
return circles = regions.map { CLCircularRegion(...) }
} onEvent: { event, currentLocation in
switch event {
case .departed(visit):
// Called when a previously-visited location was left
case .entered(region):
// Called when entering a defined region.
let notification = MyNotification(for: region)
notification.fire()
case .arrived(visit):
// Called when a visit was registered
}
}
monitor.enableVisitMonitoring = true
monitor.start()
常规 iOS 限制适用,例如:
[...] 当后台应用刷新被禁用时,无论是你的应用还是所有应用,用户必须显式启动你的应用,以继续接收所有位置相关事件。