iOS MKMapItem -如何获得访问所有成员



我使用MapKit进行本地搜索,返回一个或多个MKMapItem对象。但我可以在调试器中看到对象的成员,但我无法访问。我特别需要的是UID。

我已经试过了。placemark,但它不允许我访问UID。这看起来应该很简单。我遗漏了什么?

这行不通:NSString *uid = item.placemark.UID

这行不通:

NSDictionary *mapItemDictionary = (NSDictionary *)item;
NSString *uid = [mapItemDictionary objectForKey:@"UID"];

但是调试器命令po项显示了对象的所有成员:

Name: Shell CurrentLocation: 0 Place: <GEOPlace: 0x17014e650> 
{
address =     {
business =     (
            {
        **UID = 2478578482074921045**;
        URL = "www.shell.com";
        canBeCorrectedByBusinessOwner = 1;
        name = Shell;
        source =             (
                            {
                "source_id" = A3H0281540;
                "source_name" = "acxiom_us";
            },
                            {
                "source_id" = 2276257;
                "source_name" = localeze;
            }
        );
        telephone = "+14803968213";
    }
);

对此有任何帮助将不胜感激。下面是我使用的代码:

MKLocalSearch *localSearch = [[MKLocalSearch alloc] initWithRequest:request];
[localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error)
 {
      [response.mapItems enumerateObjectsUsingBlock:^(MKMapItem *item, NSUInteger idx, BOOL *stop)
      {
          MKPlacemark *placemark = (MKPlacemark *)item.placemark;
          NSDictionary *addressDict = placemark.addressDictionary;
          NSArray *businessArray = addressDict[@"business"];// businessArray is NIL
          NSString *uid=nil;
          if (businessArray != nil && businessArray.count >0) {
              NSDictionary *businessDict=businessArray[0];
              uid=businessDict[@"UID"];
          }
          NSLog(@"UID is %@",uid);
 }];

好的,经过大量的挖掘,似乎信息在几个私有对象中。"place"属性是一个GEOPlace,它有一个属性business,它是一个包含gebusiness对象的数组。由于这是私有数据,您不能通过属性直接访问它,但可以通过键值编码获得它。下面的代码提取UID -

[response.mapItems enumerateObjectsUsingBlock:^(MKMapItem *item, NSUInteger idx, BOOL *stop) {
    NSValue *place = [item valueForKey:@"place"];
    NSArray *businessArray = (NSArray *)[place valueForKey:@"business"];
    NSNumber *uid=nil;
    if (businessArray != nil && businessArray.count >0) {
         id geobusiness=businessArray[0];
         uid=[geobusiness valueForKey:@"uID"];
    }
    NSLog(@"UID is %@",[uid stringValue]);
 }];

由于这是私有数据结构,因此不能保证它不会更改。我也不确定App store验证过程是否会将此标记为私有api访问-因为它使用valueForKey,我认为不会,但不能保证。

相关内容

  • 没有找到相关文章

最新更新