【发布时间】:2014-06-02 14:53:27
【问题描述】:
我不知道这是否可能。
有没有办法扩展 CLLocationManager 及其协议 (CLLLocationManagerDelegate) 以便在其委托 didRangeBeacon 中接收自定义 CLBeaconRegion(从 CLBeaconRegion 扩展的类)并且信标数组包含而不是常规 CLBeacon 实例,一个来自另一个的实例 一个从 CLBeacon 扩展的类。
现在我有一个在 didRangeBeacon 委托中的实现,它准备我的自定义 CLBeaconRegion 和 CLBeacon 类的实例,并调用我在 .h 文件中定义的协议的自定义 didRangeBeacon 方法(看起来非常接近常规CLLocationManagerDelegate 协议在方法和属性方面)
也许我没有解释我自己。这是我所拥有的:
在我的 customDelegate .h 中,我有:
@class MyCustomManager;
@protocol MyCustomManagerDelegate <CLLocationManagerDelegate>
@optional
- (void)myManager:(MyCustomManager*)myManager didFoundBeacon:(MyCustomBeacon *)beacon inRegion:(MyCustomBeaconRegion *)region;
- (void)myManager:(MyCustomManager*)myManager didLostBeacon:(MyCustomBeacon *)beacon inRegion:(MyCustomBeaconRegion *)region;
- (void)myManager:(MyCustomManager*)myManager didEnterRegion:(MyCustomBeaconRegion *)region;
- (void)myManager:(MyCustomManager*)myManager didExitRegion:(MyCustomBeaconRegion *)region;
- (void)myManager:(MyCustomManager*)myManager didRangeBeacon:(NSArray *)beacons inRegion:(MyCustomBeaconRegion *)region;
@end
@interface MyCustomManager : NSObject <CLLocationManagerDelegate>
@property (weak, nonatomic) id<MyCustomManagerDelegate> delegate;
@end
然后在我的 .m 中我有:
@implementation MyCustomManager
-(void) locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(MyCustomBeaconRegion *)region{
//my code goes here
}
@end
如果我调试我的应用程序并使用断点检查 didRangeBeacons 内部,我仍然会收到 CLBeaconRegion 而不是 MyCustomBeaconRegion。在调试控制台中检查第一个信标属性,仍然是 CLBeacon 而不是 MyCustomBeacon,但是我看到列出了我的自定义信标类属性(首先出现的是 CLBeacon,然后是我的扩展类属性)
我知道我肯定做错了什么,但我不知道在哪里。我已经多次使用继承,但没有使用协议/委托和这个 CLLocationManager。我不知道我所问的是否可能。
我想知道是否可以覆盖默认委托方法,以便使用我的自定义类而不是默认协议参数类来调用它们。
【问题讨论】:
标签: ios objective-c delegates protocols