2014-09-18 21 views
5

MKMapview vị trí người dùng hiện tại không kích hoạt trong iOS-8, trước iOS-7 & iOS-6 đang hoạt động tốt.iOS 8 Mapview Vị trí hiện tại không kích hoạt

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

Trong dòng này để gọi tự động cho người sử dụng vị trí hiện tại phương pháp đại biểu

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ 
} 

nhưng nó không bắn trong iOS-8.

+0

thể trùng lặp của [iOS 8: Location Services không làm việc] (http://stackoverflow.com/questions/24062509/ios-8-location-services-not -working) –

Trả lời

6

Trong iOS8, bạn cần yêu cầu ủy quyền của người dùng trước khi nhận được vị trí của họ.

Có hai loại yêu cầu:

-[CLLocationManager requestWhenInUseAuthorization] phép bạn có được vị trí của người sử dụng chỉ khi ứng dụng được đánh thức.

-[CLLocationManager requestAlwaysAuthorization] cho phép bạn có được vị trí của người dùng ngay cả khi nó ở chế độ nền.

Bạn có thể chọn giữa chúng cho phù hợp.

Ví dụ, đặt điều này trước khi bạn bắt đầu cập nhật vị trí:

// ask for authorization 
CLLocationManager * locationManager = [[CLLocationManager alloc] init]; 
// check before requesting, otherwise it might crash in older version 
if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { 

    [locationManager requestWhenInUseAuthorization]; 

} 

Bên cạnh đó, đừng quên thêm hai phím

NSLocationWhenInUseUsageDescription 

NSLocationAlwaysUsageDescription 

vào thông tin của bạn .plist.

Để trống các giá trị để sử dụng các tin nhắn mặc định hoặc bạn có thể tùy chỉnh các giá trị của riêng mình bằng cách nhập các giá trị.

+0

Làm việc tốt, Cảm ơn. – user1418679

0

Trong iOS 8 MapView vị trí bây giờ lửa sử dụng

Bạn có thể thiết lập trong file plist của bạn

<key>NSLocationWhenInUseUsageDescription</key> 
<string>Your app name Or Other string</string> 
<key>NSLocationAlwaysUsageDescription</key> 
<string>Your app name Or Other string</string> 

Và bên mã của bạn bạn chỉ cần thực hiện điều này

CLLocationManager * locationmanager = [CLLocationManager mới ];

locationmanager.delegate = self; 
locationmanager.distanceFilter = kCLDistanceFilterNone; 
locationmanager.desiredAccuracy = kCLLocationAccuracyBest; 
[locationmanager startUpdatingLocation];  
[locationmanager requestAlwaysAuthorization]; 

- (void) locationManager: (CLLocationManager *) didUpdateLocations quản lý: (NSArray *) địa điểm {

location = [locations objectAtIndex:0]; 
[locationmanager stopUpdatingLocation]; 

}

Tôi đang sử dụng ứng dụng của tôi này có được vị trí hiện tại hoàn hảo.

3

Trong ios 8 Authorization được yêu cầu như bên dưới

NSString * osVersion = [[UIDevice currentDevice] systemVersion]; 
    if ([osVersion floatValue]>= 8.0) { 
    [_CLLocationManager requestAlwaysAuthorization]; //Requests permission to use location services whenever the app is running. 
// [_CLLocationManager requestWhenInUseAuthorization]; //Requests permission to use location services while the app is in the foreground. 
    } 
    [_CLLocationManager startUpdatingLocation]; 

Và bạn cần phải thêm hai phím trong plist

1.NSLocationAlwaysUsageDescription

2.NSLocationWhenInUseUsageDescription

enter image description here

Các vấn đề liên quan