在ios7之前,我們進(jìn)入程序提示用戶開啟定位是這樣做的,如下:
10年積累的網(wǎng)站建設(shè)、成都做網(wǎng)站經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有肇源免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
CLLocationManager * locationManager = [[CLLocationManager alloc] init];//創(chuàng)建位置管理器
//locationManager.delegate=_instance;
locationManager.desiredAccuracy=kCLLocationAccuracyBest;
locationManager.distanceFilter=100.0f;
//定位服務(wù)是否可用
BOOL enable=[CLLocationManagerlocationServicesEnabled];
//是否具有定位權(quán)限
int status=[CLLocationManager authorizationStatus];
if(!enable || status<3){
//請(qǐng)求權(quán)限
[locationManager requestWhenInUseAuthorization];
}
但是到了ios8后,發(fā)現(xiàn)定位壓根就不起作用,老是提示:
ios8定位解決如下:
先在info.plist定義key:(總是授權(quán))NSLocationAlwaysUsageDescription或者使用時(shí)授權(quán)NSLocationWhenInUseUsageDescription
在.h里面
繼承代碼CLLocationManagerDelegate
定義CLLocationManager *_locationManager;
在.m里面定義:
- (void)startTrackingLocation {
CLAuthorizationStatus status = [CLLocationManagerauthorizationStatus];
if (status ==kCLAuthorizationStatusNotDetermined) {
//總是授權(quán)
[_locationManagerrequestAlwaysAuthorization];
//每次授權(quán)一次
//[_locationManager requestWhenInUseAuthorization];
}
elseif (status ==kCLAuthorizationStatusAuthorizedWhenInUse || status ==kCLAuthorizationStatusAuthorizedAlways) {
[_locationManagerstartUpdatingLocation];
}
}
//實(shí)現(xiàn)代碼回調(diào)
#pragma mark - CLLocationManager Delegate Methods
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
switch (status) {
casekCLAuthorizationStatusAuthorizedAlways:
casekCLAuthorizationStatusAuthorizedWhenInUse:
NSLog(@"Got authorization, start tracking location");
[selfstartTrackingLocation];
break;
casekCLAuthorizationStatusNotDetermined:
[_locationManagerrequestAlwaysAuthorization];
break;
default:
break;
}
}
調(diào)用如下:
if (IOS8) {
_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate =self;
[selfstartTrackingLocation];
}
最后實(shí)現(xiàn)效果如下圖,點(diǎn)擊Allow即可定位了:
分享題目:IOS8上定位問題
文章轉(zhuǎn)載:http://jinyejixie.com/article2/ggegic.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、網(wǎng)站營銷、手機(jī)網(wǎng)站建設(shè)、定制網(wǎng)站、標(biāo)簽優(yōu)化、關(guān)鍵詞優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)