在Binding项目中实现MKAnnotation协议

时间:2014-02-02 00:26:07

标签: c# objective-c xamarin.ios cocoa-bindings ibeacon

您好,我试图在iOS Binding项目中创建以下声明。 源Objective C声明如下

@interface LeBlutrackerDevice : LeDevice <MKAnnotation>
{
    CLLocationCoordinate2D _coord;
}

@property (nonatomic,readonly,copy) NSString *title;
@property (nonatomic,readonly,copy) NSString *subtitle;
@property (nonatomic,readonly) CLLocationCoordinate2D coordinate;

@property (nonatomic, strong) NSString *svInfo;
@property (nonatomic, strong) NSString *navInfo;

@property (nonatomic,readonly) enum LE_DEVICE_STATE state;
@property (nonatomic,strong) id <LeBlutrackerDeviceDelegate> delegate;
@property (readonly) BOOL bcKeyEnabled;
- (BOOL) writeBroadcastKey: (NSData *) key;

@end

这就是我在ApiDefinition.cs中所拥有的

[Model, BaseType (typeof (LeDevice))]
public partial interface LeBlutrackerDevice : MKAnnotation
{
    [Export ("title", ArgumentSemantic.Copy)]
    string Title { get; }

    [Export ("subtitle", ArgumentSemantic.Copy)]
    string Subtitle { get; }

    [Export ("coordinate")]
    CLLocationCoordinate2D Coordinate { get; }

    [Export ("svInfo", ArgumentSemantic.Retain)]
    string SvInfo { get; set; }

    [Export ("navInfo", ArgumentSemantic.Retain)]
    string NavInfo { get; set; }

    [Export ("state")]
    LE_DEVICE_STATE State { get; }

    [Export ("delegate", ArgumentSemantic.Retain)]
    LeBlutrackerDeviceDelegate Delegate { get; set; }

    [Export ("bcKeyEnabled")]
    bool BcKeyEnabled { get; }

    [Export ("writeBroadcastKey:")]
    bool WriteBroadcastKey (NSData key);
}

我收到以下错误

Target GenerateBindings:

ApiDefinition.cs(309,48): error CS0527: Type `MonoTouch.MapKit.MKAnnotation' in interface list is not an interface

ApiDefinition.cs(313,10): warning CS0108: `SticknFind.LeBlutrackerDevice.Title' hides inherited member `MonoTouch.MapKit.MKAnnotation.Title'. Use the new keyword if hiding was intended

ApiDefinition.cs(316,10): warning CS0108: `SticknFind.LeBlutrackerDevice.Subtitle' hides inherited member `MonoTouch.MapKit.MKAnnotation.Subtitle'. Use the new keyword if hiding was intended

ApiDefinition.cs(319,26): warning CS0108: `SticknFind.LeBlutrackerDevice.Coordinate' hides inherited member `MonoTouch.MapKit.MKAnnotation.Coordinate'. Use the new keyword if hiding was intended

是否有人试图为SticknFind SDK创建绑定?请告诉我,因为我非常乐意在GitHub上发布最终结果。

如果我尝试从IMKAnnotation继承,我会收到以下错误

btouch: No [Export] attribute on property SticknFind.LeBlutrackerDevice.Coordinate
Task "BTouch" execution -- FAILED

1 个答案:

答案 0 :(得分:3)

您希望继承接口而不是类型,这是导致第一个CS0527错误的原因。

这是用[Protocol]属性修饰的界面(因此它将与ObjC声明匹配)。它还将解决后来的CS0108错误,因为该类型的额外成员不是协议的一部分。

所以这应该解决它:

[BaseType (typeof (LeDevice))]
public partial interface LeBlutrackerDevice : IMKAnnotation {
   ...
}