0

我有一个 CLregions 数组,这是我的代码:

NSArray *_regionArray;
NSArray *_geofences_regions;

... in the ViewDidLoad
_geofences_regions = [self buildGeofenceData];
....


- (NSArray*) buildGeofenceData {
    NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"regions" ofType:@"plist"];
    _regionArray = [NSArray arrayWithContentsOfFile:plistPath];

    NSMutableArray *geofences = [NSMutableArray array];
    for(NSDictionary *regionDict in _regionArray) {
        CLRegion *region = [self mapDictionaryToRegion:regionDict];
        [geofences addObject:region];
    }

    return [NSArray arrayWithArray:geofences];
}

- (CLRegion*)mapDictionaryToRegion:(NSDictionary*)dictionary {
    NSString *title = [dictionary valueForKey:@"title"];

    CLLocationDegrees latitude = [[dictionary valueForKey:@"latitude"] doubleValue];
    CLLocationDegrees longitude =[[dictionary valueForKey:@"longitude"] doubleValue];
    CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(latitude, longitude);

    CLLocationDistance regionRadius = [[dictionary valueForKey:@"radius"] doubleValue];


    return [[CLRegion alloc] initCircularRegionWithCenter:centerCoordinate
                                                   radius:regionRadius
                                               identifier:title];
}

在下面的代码中,the property identifier is not found on object of type id.

这是为什么?不应该_geofences_regios[i]返回 CLRegion 吗?

/*check for region*/
                        CLLocationCoordinate2D coordinate = [bestLocation coordinate];
                        for (int i=0; i<[_geofences_regions count]; i++) {
                            if ([_geofences_regions[i] containsCoordinate:coordinate]) {
                                [self.delegate locationManager:self regionEntered:_geofences_regions[i].identifier ];

} } /结束区域检查/

请回答上述问题,不要建议我使用其他委托方法,如 didEnterRegion。

谢谢!

4

1 回答 1

0

这是因为数组返回的对象,默认情况下是id没有identifier属性的类型,您可以进行强制转换以避免错误:

[self.delegate locationManager:self regionEntered:((CLRegion*)_geofences_regions[i]).identifier ];
于 2013-09-08T13:26:49.150 回答