iOS 8 Core Location 每次都在 WiFi 上工作,在 4G 上时断时续

标签 ios objective-c ios8 core-location

所以当我连接到 WiFi 时它可以工作。但是在 4G 上,它只有在我使用 Wifi 并且它已经有位置的情况下才有效。很多时候没有 WiFi,手机会说它正在使用我的位置,但它不会更新标签,也不会将坐标上传到服务器。这是代码:

- (void)viewDidLoad {
    [super viewDidLoad];

    if (nil == locationManager)
        locationManager = [[CLLocationManager alloc] init];
        locationManager = [[CLLocationManager alloc] init];
        locationManager.delegate = self;
        locationManager.desiredAccuracy = kCLLocationAccuracyBest;

    if ([self->locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
        [self->locationManager requestWhenInUseAuthorization];
    }

}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
    CLLocation *newLocation = [locations lastObject];
    NSString *locationLat = [NSString stringWithFormat:@"%.8f", newLocation.coordinate.latitude];
    NSString *locationLong = [NSString stringWithFormat:@"%.8f", newLocation.coordinate.longitude];

    latLongLabel.text = [NSString stringWithFormat:@"Lat: %@ - Long%@",locationLat,locationLong];
    [self postLocation:locationLat secondArg:locationLong];

}
- (void)postLocation: (NSString *)latitudeString secondArg:(NSString *)longitudeString {

//POST COORDINATES TO MY SERVER

}

- (IBAction)startUpdating:(id)sender {

    [locationManager startUpdatingLocation];

}

最佳答案

我怀疑当你使用 4G 时,位置更新仍然可以正常工作(虽然 wifi 三角测量使它们更精确但只有 Apple 知道如何实现,因为实现是私有(private)的),但是发送那些可能有问题通过 4G 连接快速或可靠地向服务器发送值。 (例如在伦敦,周围有很多人,速度很慢)

您可以通过简单地将位置更新直接记录到 View 上的某个 UIlabel 来缩小调试范围,而不是通过服务器基础设施。

作为最后的手段,我会确保 您将 CLActivityType 属性设置为 CLActivityTypeFitness 并且 pausesLocationUpdatesAutomatically 设置为 NO

关于iOS 8 Core Location 每次都在 WiFi 上工作,在 4G 上时断时续,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28224764/

相关文章:

iphone - 在 CIFilter : getting empty image 中使用来自 CIColor 的 CIImage

ios - 如何将 UIActivityIndi​​catorView 放入 UIAlertController 中?

ios - 如何模拟多个 iOS 客户端连接到一个服务器?

ios - 需要在不压缩的情况下在 NSData 中加载 "original"图像

ios - UINavigationController 不会在推送的 UIViewController 上调用 viewDidLoad

ios - 如何在swift 3中每天在特定时间触发本地通知

ios - 重新加载 UItableview 未更新标签

swift - 如何在 iOS 8 中以编程方式隐藏状态栏

cocoa - 对 Xcode 6 中创建胖静态库的不同过程感到困惑

iOS8自定义键盘在模拟器上可以换主题,真机上不行