【问题标题】:didupdatelocation not called repetedly in ios 7.1在 ios 7.1 中没有重复调用 didupdatelocations
【发布时间】:2014-04-10 12:09:55
【问题描述】:

我正在开发一个具有位置的应用程序并成功获取坐标,然后我正在调用 web 服务来存储坐标,但是当我使用 ios 7.1 设备时,不会重复调用 didupdatelocation 方法。这是我的代码

if ([CLLocationManager locationServicesEnabled])
    {
        self.locationManager = [[CLLocationManager alloc] init];
        self.locationManager.pausesLocationUpdatesAutomatically=NO;

        self.locationManager.delegate = self;
        self.locationManager.desiredAccuracy=kCLLocationAccuracyBest;
        [self.locationManager startUpdatingLocation];
    }

还有这个

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    if (UIApplication.sharedApplication.applicationState == UIApplicationStateActive)
    {
        CLLocationCoordinate2D center;

        center.latitude = [[locations objectAtIndex:([locations count]-1)] coordinate].latitude;
        center.longitude = [[locations objectAtIndex:([locations count]-1)] coordinate].longitude;

        _point = [[MKPointAnnotation alloc] init];
        _point.coordinate = center;

        if(appDelegate.strVehicleType!=nil)
        {
            [self checkInternet];
        }

        NSLog(@"Changed");

        [_locationManager stopUpdatingLocation];
    }
    else
    {
        CLLocationCoordinate2D center;

        center.latitude = [[locations objectAtIndex:([locations     count]-1)] coordinate].latitude;
        center.longitude = [[locations objectAtIndex:([locations     count]-1)] coordinate].longitude;

        _point = [[MKPointAnnotation alloc] init];

        _point.coordinate = center;

        if(appDelegate.strVehicleType!=nil)
        {
            [self checkInternet];
        }

        NSLog(@"Location Changed in Background")
        ;
        [_locationManager stopUpdatingLocation];
    }
}

我已经尝试了上面的代码,位置在 ios 6 和 ios 7 中重复更新,但在 7.1 中没有更新,所以请任何人知道问题出在哪里?或者他们有什么不同的使用方法。

提前感谢。

【问题讨论】:

标签: ios cllocationmanager


【解决方案1】:

是的,因为您的设备中的后台应用刷新已关闭,所以...

转到常规>“后台应用刷新”>打开。

和常规>“后台应用刷新”>您的应用>打开。

解决您的问题

【讨论】:

  • 后台应用刷新已开启,我已将其关闭并重新开启,然后进行测试,但结果仍然相同..
  • 应用程序终止并重新启动
  • 并删除此行 [_locationManager stopUpdatingLocation];来自您的代码
【解决方案2】:

如果您使用模拟器进行测试,请重置模拟器。 如果您正在使用设备,请从中删除应用程序。

在.h文件中添加#import <CoreLocation/CoreLocation.h>框架

在 .h 文件中添加委托 CLLocationManagerDelegate

在 viewDidload 中放下面的代码

if ([CLLocationManager locationServicesEnabled])
{
    locationManager = [[CLLocationManager alloc] init];
    locationManager.pausesLocationUpdatesAutomatically=YES;

    locationManager.delegate = self;
    locationManager.desiredAccuracy=kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];
}

====== 那么

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    if (UIApplication.sharedApplication.applicationState == UIApplicationStateActive)
    {

        NSLog(@"Active");

    }
    else
    {
        NSLog(@"Non Active");
    }
}

运行应用程序,它会提示您“应用程序名称”想使用您当前的位置”,按“确定”

如果您使用模拟器进行测试,请执行以下步骤:

来自模拟器的工具栏 调试 > 位置 > 苹果

执行这些步骤后,模拟器更改位置和方法将调用。

【讨论】:

  • no @Viky 相同的结果 didupdatelocations 没有被调用。
  • 我正在使用 ios 7.1 的设备
  • 我已经编辑了我的答案如果您使用的是模拟器,请执行此步骤
  • 这段代码在 ios 6 和 ios 7 中像魅力一样工作,但在 ios7.1 中不起作用,也使用了不同的方法来开始位置更新,给定距离过滤器,但仍然是同样的问题......跨度>
  • 我正在测试 iOS 7.1 及其工作。请尝试您的代码,我只是复制您的代码并且它工作正常...
猜你喜欢
  • 2014-11-28
  • 2016-10-24
  • 2016-07-11
  • 1970-01-01
  • 1970-01-01
  • 2014-07-07
  • 2023-03-26
  • 2014-04-13
  • 2016-01-04
相关资源
最近更新 更多