기기의 위치를 대략적인 서버로 업데이트해야하는 앱을 개발 중입니다. 데이터에서 700 미터.iOS 응용 프로그램의 지역 모니터링 제한
배경 및 전경 모드에서 성공적으로 달성 할 수 있습니다. 앱이 종료 될 때 앱이 종료 될 때 앱이 종료 될 때 중요한 업데이트가 발생합니다. 즉, 앱의 종료 위치에 중요한 변경 사항이 구현되었지만 기기가 임의의 방식으로 위치 변경을 알리고 매우 부정확하거나 위치 업데이트가 지연되는 경우가 있습니다. 2-3 킬로미터에 위치 업데이트를 수신하고 때로는 7 킬로미터 거리에서도 수신 할 수 없습니다.
내 팀원 중 한 명이 앱 종료 지점 모니터링을 구현하라는 제안을 받았지만 이제는 지역 모니터링을 구현했지만 제대로 작동하지 않고 모니터링 할 수있는 지역은 최대 20 개까지만 읽을 수 있습니다. 앱에서
import UIKit
import CoreLocation
import XCGLogger
//import SwiftLocation
// MARK: - AppDelegate
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate
{
var window: UIWindow?
var locationManager: CLLocationManager!
var currentLocation: CLLocationCoordinate2D?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
if launchOptions != nil
{
if (launchOptions![UIApplicationLaunchOptionsLocationKey] != nil)
{
if let location = locationManager.location?.coordinate {
startRegionMonitoring(location)
}
}
}
setupLocalNotifications()
setupLocationManager()
return true
}
func setupLocationManager()
{
if (locationManager == nil)
{
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.pausesLocationUpdatesAutomatically = false
locationManager.distanceFilter = CLLocationDistance(100.0)
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
if #available(iOS 9.0, *) {
locationManager.allowsBackgroundLocationUpdates = true
}
}
}
func applicationWillTerminate(application: UIApplication)
{
if currentLocation == nil
{
return
}
// create a region around current location and monitor enter/exit
startRegionMonitoring(currentLocation!)
}
func startRegionMonitoring(location: CLLocationCoordinate2D)
{
let region = CLCircularRegion(center: location, radius: 100.0, identifier: "manish")
region.notifyOnExit = true
region.notifyOnEntry = true
locationManager.startMonitoringForRegion(region)
}
// MARK: - Local notifications
func setupLocalNotifications()
{
let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
}
func showLocalNotification(message: String)
{
let localNotification = UILocalNotification()
localNotification.alertBody = message;
localNotification.fireDate = NSDate(timeIntervalSinceNow: 1.0)
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
}
}
extension AppDelegate
{
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus)
{
if status == .AuthorizedAlways {
locationManager.startUpdatingLocation()
}
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
currentLocation = locations.first?.coordinate
showLocalNotification("didUpdateLocations: \(currentLocation)")
}
func locationManager(manager: CLLocationManager, didEnterRegion region: CLRegion)
{
showLocalNotification("Entered region: \(region.identifier)")
}
func locationManager(manager: CLLocationManager, didExitRegion region: CLRegion)
{
showLocalNotification("Exited region: \(region.identifier)")
if let location = manager.location?.coordinate {
startRegionMonitoring(location)
}
}
}
가 어떻게 위치를 업데이트 할 수있는 응용 프로그램이 종료 된 경우에도 :
여기에 내가 시도 아래의 샘플 코드는 무엇입니까? 위의 코드에서 잘못된 것이 있습니까?
나는 위치 업데이트가 필요합니다. 코드와 설명에 도움이된다면 도움이 될 것입니다. –