c# - 在 Binding 项目中实现 MKAnnotation 协议(protocol)

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

您好,您好,您正在尝试在 iOS 绑定(bind)项目中创建以下声明。 源 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 创建绑定(bind)吗?请让我知道,因为我非常乐意在 GitHub 上发布最终结果。

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

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

最佳答案

您想从接口(interface)而不是类型继承,这就是导致第一个 CS0527 错误的原因。

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

所以这应该可以解决:

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

关于c# - 在 Binding 项目中实现 MKAnnotation 协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21505518/

相关文章:

c# - 通过 GSM 调制解调器使用 AT 命令在 C# 中发送 Unicode 消息(例如波斯语和阿拉伯语)

c# - 在 RavenDB 中按 ID 排序

c# - 如何在运行时更改 HttpRuntime 设置(例如 WaitChangeNotification)?

iphone - 如何检测用户是否拒绝使用我的默认位置?

android - 点击当前选项卡刷新页面时的 Xamarin.Forms TabbedPage 事件

xamarin.ios - 使用 Xcode 和 Monotouch 设计器中的图像

c# - 管理调试和发布连接字符串

ios - 根据物体的速度和旋转找到所需的点

ios - LayerKit 将附加信息设置为 LYRIdentity

iphone - 开发分布式 iPhone/iPad 应用程序的框架建议