1.被拒說明
LEGAL: PRIVACY - LOCATION SERVICES
Legal - 5.1.5
Your app uses background location services but does not clarify the purpose of its use in the location modal alert as required in the iOS Human Interface Guidelines.
We've attached screenshot(s) for your reference.
Next Steps
Please revise the NSLocationAlwaysUsageDescription value in the info.plist to specify the intended purpose of using the user's location while the app is in the background.
Resources
For additional information and instructions on configuring and presenting an alert, see the Accessing User Data section of the iOS Human Interface Guidelines and the Information Property List Key Reference.
2.被拒原因
沒有描述需要定位的原因琢锋。
3.解決方法
在下圖所示的位置填寫需要定位的原因若厚。
在工程Info.plist文件中添加需要展示的信息米间,先添加兩個字段NSLocationAlwaysUsageDescription
NSLocationWhenInUseUsageDescription
秉颗,如圖所示:
4.定位用戶位置的代碼
引入頭文件#import <CoreLocation/CoreLocation.h>
添加代理CLLocationManagerDelegate
- 創(chuàng)建定位管理器:
CLLocationManager *_locationManager;
// 初始化定位管理器
_locationManager = [[CLLocationManager alloc] init];
// 設置代理
_locationManager.delegate = self;
// 設置定位精確度到米
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
// 設置過濾器為無
_locationManager.distanceFilter = kCLDistanceFilterNone;
// 開始定位
// 取得定位權限昧辽,有兩個方法瘪校,取決于你的定位使用情況
// 一個是requestAlwaysAuthorization蝎亚,一個是requestWhenInUseAuthorization
[_locationManager requestWhenInUseAuthorization];//這句話ios8以上版本使用九孩。 使用期間訪問位置
[_locationManager startUpdatingLocation];
- CLLocationManager代理
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSString * lng = [NSString stringWithFormat:@"%lf", newLocation.coordinate.longitude];//經(jīng)度
NSString * lat = [NSString stringWithFormat:@"%lf", newLocation.coordinate.latitude];//緯度
NSTimeZone *sysZone = [NSTimeZone systemTimeZone];//系統(tǒng)時區(qū)
//系統(tǒng)會一直更新數(shù)據(jù),直到選擇停止更新发框,因為我們只需要獲得一次經(jīng)緯度即可躺彬,所以獲取之后就停止更新
[_locationManager stopUpdatingLocation];
NSLog(@"----lng = %@,lat = %@,syszone = %@",lng,lat,sysZone);
}