CLRegion上找不到属性标识符

时间:2013-09-08 13:16:27

标签: ios

我有一个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。

谢谢!

1 个答案:

答案 0 :(得分:0)

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

[self.delegate locationManager:self regionEntered:((CLRegion*)_geofences_regions[i]).identifier ];