iOS MKMapItem-如何获得对所有成员的访问权限? [英] iOS MKMapItem - how get access to all members?

查看:93
本文介绍了iOS MKMapItem-如何获得对所有成员的访问权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using MapKit to do a local search which returns one or more MKMapItem objects. But there are members of the object I can see in the debugger but I can't access. The one I particularly need is UID.

我尝试了item.placemark,但是它不允许我访问UID.这似乎应该很简单.我在这里想念什么?

I have tried item.placemark, but it does not let me access the UID. This seems like it should be really simple. What am I missing here?

这不起作用: NSString * uid = item.placemark.UID

This does not work: NSString *uid = item.placemark.UID

这不起作用:

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

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

But the debugger command po item shows me all the members of the object:

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";
    }
);

任何对此的帮助将不胜感激.这是我正在使用的代码:

Any help with this would be appreciated. Here is the code I'm using:

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);

 }];

推荐答案

好,因此,在进行大量挖掘之后,似乎该信息位于两个私有对象中. 位置"属性是GEOPlace,它具有业务属性,该属性是包含GEOBusiness对象的数组.由于这是私有数据,因此您不能直接通过属性访问它,但是可以通过键值编码来获取它.以下代码提取了UID-

Ok, so after a lot of digging it seems that the information is in a couple of private objects. The "place" property is a GEOPlace, and this has a property, business, which is an array that contains a GEOBusiness object. Since this is private data you cannot access it directly via properties, but you can get it via key-value encoding. The following code extracts the 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,我认为不会,但是没有保证.

As this is private data structures there is no guarantee that it won't change. I am also unsure whether the App store validation process will flag this as private api access - Since it is using valueForKey I don't think it will, but there are no guarantees.

这篇关于iOS MKMapItem-如何获得对所有成员的访问权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆