ব্যাকগ্রাউন্ড লোকেশন পেতে CoreLocation ফ্রেমওয়ার্ক এবং CLLocationManager ব্যবহার করুন।
Info.plist-এ পারমিশন যোগ করুন —
- Privacy - Location Always and When In Use Usage Description
- Privacy - Location When In Use Usage Description
কোড —
var locationManager: CLLocationManager?
override func viewDidLoad() {
super.viewDidLoad()
locationManager = CLLocationManager()
locationManager?.delegate = self
locationManager?.requestAlwaysAuthorization()
}
locationManager?.startUpdatingLocation()
locationManager?.startMonitoringSignificantLocationChanges()
locationManager?.allowsBackgroundLocationUpdates = true
didUpdateLocations ডেলিগেট মেথডে লোকেশন সার্ভারে পাঠান —
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
// API কল করে লোকেশন আপডেট করুন
}