【问题标题】:[__NSDictionaryI bytes]: unrecognized selector sent to instance[__NSDictionaryI bytes]:发送到实例的无法识别的选择器
【发布时间】:2017-02-07 07:03:13
【问题描述】:

这是我获取邮政编码的代码。

CLGeocoder *reverseGeocoder = [[CLGeocoder alloc] init];

[reverseGeocoder reverseGeocodeLocation:locationManager.location completionHandler:^(NSArray *placemarks, NSError *error)
 {
      NSLog(@"reverseGeocodeLocation:completionHandler: Completion Handler called!");
      if (error){
          NSLog(@"Geocode failed with error: %@", error);
          return;
      }

      NSLog(@"Received placemarks: %@", placemarks);             
      CLPlacemark *myPlacemark = [placemarks objectAtIndex:0];
      NSString *countryCode = myPlacemark.ISOcountryCode;
      NSString *countryName = myPlacemark.country;
      NSLog(@"My country code: %@ and countryName: %@", countryCode, countryName);

}];

但它总是因NSInvalidArgumentException 错误而崩溃,

2017-02-07 12:29:58.124 CBB[3654:270750] Lat : 42.771389  Long : 

129.423340
2017-02-07 12:29:58.967 CBB[3654:270750] -[__NSDictionaryI bytes]: unrecognized selector sent to instance 0x600000473b80
2017-02-07 12:29:59.011 CBB[3654:270750] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI bytes]: unrecognized selector sent to instance 0x600000473b80'

【问题讨论】:

  • 你在哪一行遇到这个崩溃
  • 使用调试检查 myPlacemark,您是否获得了您期望的准确数据?我认为您在 CLPlacemark *myPlacemark = [placemarks objectAtIndex:0];line. 中遇到问题
  • 你看到这个NSArray *placemarks了吗,它重新生成数组
  • @Anbu.Karthik 是的。调用反向地理代码方法时崩溃。
  • 其他地方有问题

标签: ios objective-c clgeocoder


【解决方案1】:

bytes 是 NSData 的属性,所以你使用 NSDictionary 作为 NSData。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-28
    • 2012-07-24
    相关资源
    最近更新 更多