【问题标题】:Current location alert and dot not showing in iOS8当前位置警报和点未在 iOS8 中显示
【发布时间】:2014-11-14 05:14:07
【问题描述】:

从 iOS7 移动到 iOS8,我的应用没有显示当前位置的警报或蓝点。我试图根据我在这里阅读的内容更改我的代码,现在警报正在显示,但只是一瞬间,没有机会选择任何东西。不用说,蓝点也不存在。 我的代码是:

地图名称.h

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>

@interface MapName : UIViewController <MKMapViewDelegate>

@property (strong, nonatomic) IBOutlet MKMapView *MapName;
@property (nonatomic, retain) CLRegion *region;
@property (nonatomic) BOOL showsUserLocation;

@end

地图名称.m

//in the (void)viewDiDLoad section
CLLocationManager *locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = _MapName;  //Assigning to 'id<CLLocationManagerDelegate>' from incompatible type 'MKMapView*_strong' warning showing here
[locationManager requestWhenInUseAuthorization];
[locationManager startUpdatingLocation];
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
if (status == kCLAuthorizationStatusDenied ||
    status == kCLAuthorizationStatusAuthorizedWhenInUse) {
    //UIApplication -openUrl: UIApplicationOpenSettingsURLString //this is the example shown on WWDC
}

[locationManager requestWhenInUseAuthorization];
[locationManager startMonitoringForRegion:_region];

我已将带有消息(我在警报中看到)的 NSLocationWhenIsUseUsageDescription 字符串添加到 Info.plist

【问题讨论】:

    标签: ios8 alert core-location cllocationmanager xcode6


    【解决方案1】:

    问题解决了:

    地图名称.h

    #import <UIKit/UIKit.h>
    #import <MapKit/MapKit.h>
    #import <CoreLocation/CoreLocation.h>
    
    
    @interface MapName : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate>
    
    @property (strong, nonatomic) IBOutlet MKMapView *MapName;
    @property (strong, nonatomic) CLLocationManager *locationManager;
    
    @end
    

    地图名称.m

    - (void)viewDidLoad
    {
    [super viewDidLoad];
    
    self.locationManager = [[CLLocationManager alloc]init];
    self.locationManager.delegate = self;
    if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
        [self.locationManager requestWhenInUseAuthorization];
    }
    [self.locationManager startUpdatingLocation];
    
    //Center the map
    [self gotoLocation];
    
    //Show current position
    _MapName.showsUserLocation = YES;
    
    }
    

    首先将键 NSLocationWhenInUseUsageDescription 作为字符串添加到 Info.plist 中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-15
      相关资源
      最近更新 更多