【发布时间】:2012-09-24 20:15:00
【问题描述】:
我试图在我的应用程序中获取 iphone 的位置数据,但由于某种原因,我一直在我的 switch 块中点击 kclAuthorizationStatusNotDetermined。
我知道在模拟器上启用了定位服务,并且我的 CLLocationManager 在我的头文件中声明,所以我知道它存在。
我的代码如下:
if ([CLLocationManager locationServicesEnabled])
{
//check if this app is allowed to access geolocation
switch ([CLLocationManager authorizationStatus])
{
case kCLAuthorizationStatusNotDetermined:
// do something
NSLog(@"Status not determined");
break;
case kCLAuthorizationStatusDenied:
//do something
NSLog(@"Status denied");
break;
case kCLAuthorizationStatusRestricted:
//do something
NSLog(@"Status restricted");
break;
case kCLAuthorizationStatusAuthorized:
[manager startUpdatingLocation];
CLLocation *currentCoords = [manager location];
NSString *location = [currentCoords description];
UIAlertView *gps = [[UIAlertView alloc]
initWithTitle:@"Current Location" message:location delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
[gps show];
//getHails or getDetails();
break;
}
}
我错过了什么吗?提前感谢您的帮助
【问题讨论】:
标签: iphone objective-c ios geolocation