【问题标题】:Core location alerts核心位置警报
【发布时间】:2012-11-30 02:58:12
【问题描述】:
【问题讨论】:
标签:
iphone
ios
alert
core-location
【解决方案1】:
这是访问您当前位置时的警报,当您使用CLLocationManager访问用户当前位置时,它会自动询问
-(void)getLocation
{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLLocationAccuracyHundredMeters;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
NSLog(@"eee%f",locationManager.location.coordinate.latitude);
// Start updating location changes.
[locationManager startUpdatingLocation];
}
- (void)startUpdatingCurrentLocation
{
//NSLog(@"STARTUPDATELOCATION");
// if location services are restricted do nothing
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied ||
[CLLocationManager authorizationStatus] == kCLAuthorizationStatusRestricted )
{
return;
}
// if locationManager does not currently exist, create it
if (!locationManager)
{
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
locationManager.distanceFilter = 10.0f; // we don't need to be any more accurate than 10m
}
[locationManager startUpdatingLocation];
// [self showCurrentLocationSpinner:YES];
}
阅读CLLocationManager Class Reference了解更多信息
【解决方案2】:
好吧,这该死的简单。它被称为UIAlertView,用于发送通知非常常见。它们应该用于通知用户一些事情,而不是太多的交互。
编码明智,这里是一些基本的设置文本:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Alert Body" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];
显示警报:
[alert show];
如果您想要其他按钮标题,您需要将delegate 设置为self,并在您的.h 文件中与UIAlertViewDelegate 保持一致。 Here Is The Reference To The Delegate 并且您基本上想要实现 clickedButtonAtIndex: 方法并使用索引来找出用户按下了哪个按钮并执行操作。
Do not misuse alert views.