相关疑难解决方法(0)

didEnterRegion为我的所有地理围栏开火

当GPS进入一个确定的区域时,我的所有地理围栏都会触发,起初我认为这是因为半径,但是即使在减半之后我也遇到了同样的问题.

import UIKit
import CoreLocation


class itemDesc {
    var title: String
    var coordinate: CLLocationCoordinate2D
    var regionRadius: CLLocationDistance
    var location: String
    var type: String

    init(title: String, coordinate: CLLocationCoordinate2D, regionRadius: CLLocationDistance, location: String, type: String) {
        self.title = title
        self.coordinate = coordinate
        self.regionRadius = regionRadius
        self.location =  location
        self.type = type
    }

}

class ViewController:  UIViewController, CLLocationManagerDelegate {

    let locationManager = CLLocationManager()

    override func viewDidLoad() {

        super.viewDidLoad()
        locationManager.delegate = self
        locationManager.requestAlwaysAuthorization()
        locationManager.startUpdatingLocation()
        locationManager.desiredAccuracy = kCLLocationAccuracyBest

        setupData()
    }

    func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: …
Run Code Online (Sandbox Code Playgroud)

core-location cllocationmanager cllocation swift

12
推荐指数
1
解决办法
511
查看次数

区域监控iOS 7上的故障 - 同时发出多个通知

我一直在iOS上开发区域监控大约2个月.最近我们发现了一个小故障,同时在一定半径范围内(约4.7KM或4700米)触发了所有区域.设备的当前位置甚至不靠近任何区域.我不确定是什么原因引发了这一事件.我搜索了StackOverFlow,Apple Developer论坛等,我没有发现任何与我面临的类似问题.

在我正在开发的应用程序中,我们正在监控城市内的8个区域(吉隆坡).有一次,我的同事发现他的手机同时触发了4个地区通知.下面是显示其位置,所有受监控区域,触发4区域通知的潜在半径的地图.

iOS区域监控

  • 绿色标记是接收通知时设备的位置.
  • 蓝色圆圈是设备的潜在半径(约4700米),其覆盖了将通知发送到设备的4个区域.
  • 红色圆圈是每个区域的半径.
  • 地图上还有其他2个区域从不发送通知(从不覆盖在蓝色圆圈下)

触发通知的屏幕截图:

iOS区域监控故障

这是我的位置管理器代码: -

CLLocationManager *locationManager = [LocationTracker sharedLocationManager];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
locationManager.distanceFilter = kCLDistanceFilterNone;
Run Code Online (Sandbox Code Playgroud)

这是我的didEnterRegion代码: -

-(void)locationManager:(CLLocationManager *)manager 
        didEnterRegion:(CLRegion *)region{

NSString* message = [NSString stringWithFormat:@"Message"];        
UIApplicationState state = [[UIApplication sharedApplication] applicationState];

if (state == UIApplicationStateBackground || state == UIApplicationStateInactive)
{
   UILocalNotification *notification = [[UILocalNotification alloc] init];
   notification.fireDate = [NSDate date];
   NSTimeZone* timezone = [NSTimeZone defaultTimeZone];
   notification.timeZone = timezone;
   notification.alertBody = message;
   notification.alertAction = @"Show";
   notification.soundName = UILocalNotificationDefaultSoundName; …
Run Code Online (Sandbox Code Playgroud)

objective-c core-location cllocationmanager ios ios7

5
推荐指数
1
解决办法
4187
查看次数

向位置管理器请求状态时,CLRegionState即将变为未知状态?

我在启动区域监视时正在构建与区域监视有关的功能,我在请求状态,如下代码所示。在某些设备上,我一直都在获取区域状态“未知”。如果我打开或关闭Wifi或将充电器插入其中。它开始正常工作。如何使它在蜂窝网络上更可靠?请注意,在进行任何区域监视或状态请求调用之前,我已获得用户的所有位置权限。

private func initiateLocationManager() {
    locationManager = CLLocationManager()
    locationManager.delegate = self
    locationManager.distanceFilter = kCLLocationAccuracyBest
    locationManager.requestAlwaysAuthorization()
}

func startMonitoring(alarm: StationAlarm) {
    if LocationManager.sharedInstance.isRegionMonitoringAvailable() {
        let coordinate = CLLocationCoordinate2D(latitude: stationLatitude, longitude: stationLongitude)

        // 1
        let region = CLCircularRegion(center: coordinate, radius: CLLocationDistance(radius * 1000), identifier: alarm.alarmId)

        // 2
        region.notifyOnEntry = true
        region.notifyOnExit = false

        // 4
        locationManager.startMonitoring(for: region)
        Utility.delay(0.1) { [weak self] in
            self?.locationManager.requestState(for: region)
        }

    }
}

func locationManager(_: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion) {
    Log.event("Region State is \(state.rawValue)")
}
Run Code Online (Sandbox Code Playgroud)

core-location ios

1
推荐指数
1
解决办法
343
查看次数