【问题标题】:can't get location on iOS - doesn't call delegate methods无法在 iOS 上获取位置 - 不调用委托方法
【发布时间】:2013-02-04 16:56:20
【问题描述】:

iOS 6 下的 locationManager 有问题。

-(void) getLocationTest {
// Create a location manager instance to determine if location services are enabled. This manager instance will be
// immediately released afterwards.

manager = [[CLLocationManager alloc] init];
if (![manager locationServicesEnabled]) {
    UIAlertView *servicesDisabledAlert = [[UIAlertView alloc] initWithTitle:@"Location Services Disabled" message:@"You currently have all location services for this device disabled. If you proceed, you will be asked to confirm whether location services should be reenabled." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [servicesDisabledAlert show];
    //[servicesDisabledAlert release];
}
manager.delegate = self;
manager.desiredAccuracy = kCLLocationAccuracyKilometer;
// Set a movement threshold for new events.
manager.distanceFilter = 500;
[manager startUpdatingLocation];

//[manager release];
}





-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
double testDe = 2.434;
testDe = testDe * 2;
}



-(void)locationManager:(CLLocationManager *)manager
 didUpdateLocations:(NSArray *)locations {
CLLocation *location = [locations objectAtIndex:0];
double locDouble = location.coordinate.latitude;
NSString* locName = [[NSString alloc] initWithFormat:@"Hello, %f!", locDouble];
//[locations lastObject];
//NSLog(@"lat%f - lon%f", location.coordinate.latitude, location.coordinate.longitude);
}


-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
double testD = 2.434;
testD = testD * 2;
}

我在所有委托方法中都有断点,但没有一个被调用。 有人知道我在做什么错吗?或者我怎样才能找出错误在哪里?

我将不胜感激每一个答案! 谢谢!

【问题讨论】:

  • 应用是否使用 ARC? manager 是否被声明为强属性?

标签: ios delegates location locationmanager


【解决方案1】:

您是在设备上还是在模拟器中进行测试?在模拟器中,您必须从模拟器应用程序菜单中手动设置一些位置。它在 Debug/Location/ 中。

【讨论】:

  • 感谢您的提示。但我激活了调试位置,模拟器告诉我他在顶部的这个小 gps 标志上有位置。而且我认为,如果他没有找到任何位置,他至少必须跳入 didFailWithError 委托?
  • 好吧,正如安娜卡列尼娜已经问过的,经理是一个强大的财产吗?也许它被释放了。是否调用了 -(void)getLocationTest 方法?
  • 哦,抱歉,还没有看到这个。 ARC 已启用。这是好事还是坏事?我尝试了弱属性和强属性,但没有帮助。 -(void)getLocationTest 方法被调用并工作......:/
  • @Mex,保持经理 strong 属性并在 getLocationTest 中,尝试将 alloc+init 更改为:self.manager = [[CLLocationManager alloc] init];(将 self. 放在前面)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-07-16
  • 1970-01-01
  • 1970-01-01
  • 2015-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多