【问题标题】:MapKit crashing after adding new authorization processMapKit 在添加新的授权过程后崩溃
【发布时间】:2014-11-15 07:40:03
【问题描述】:

我正在尝试让 Map Kit 将当前用户的位置显示为预定义的大小。

一切正常,但自从更新到 Xcode 6 和 iOS 8 后,情况发生了变化。

我已经实施了必要的授权,现在应用程序崩溃了。带有*** 的代码是系统似乎有问题的代码。

这里是 Map.m

#import "MRVCMapViewController.h"
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
@import CoreLocation;

@interface MRVCMapViewController ()

@end

@implementation MRVCMapViewController
@synthesize mapView;

- (void)viewDidLoad {
     [super viewDidLoad];

     //location permission

     self.locationManager = [[CLLocationManager alloc] init];
     self.locationManager.delegate = self;


    if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
    {
        [self.locationManager requestWhenInUseAuthorization];
    }
    [self.locationManager startUpdatingLocation];

    //mapview settings

    self.mapView.delegate = self;
    self.mapView.showsUserLocation = YES;
}

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation   *)userLocation
{
    ***MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate,   800, 800);
     [self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];***
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

【问题讨论】:

  • 每当说“应用程序崩溃”时,始终包含控制台中显示的确切崩溃消息。

标签: ios mkmapview mapkit ios8 mkuserlocation


【解决方案1】:

您尚未检查 userLocation 值是否有效。在尝试将其用于任何事情之前,您应该确保它不是 nil

【讨论】:

  • 嗨,克雷格,代码减去用户权限在更新之前工作正常。
  • 您是否尝试检查 userLocation 不为零?也许在它能够及时获得位置之前。也许在 iOS 8 下,获取位置并首先发送nil 需要更长的时间。这很容易检查,并且没有您提供有关崩溃原因的更多详细信息,这是我能建议的最佳选择。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-02-05
  • 2019-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-24
相关资源
最近更新 更多