0

我在使用 Objective Sharpie 进行绑定时遇到了一些问题。我正在将IndoorAtlasiOS 本机 sdk 与 Xamarin.ios 绑定。

问题是在实现协议方法时,因为这些方法没有被调用。我们需要特殊处理吗?

我正在附加 API 定义文件和实现文件。

// @protocol IALocationManagerDelegate 
[Protocol, Model]
[BaseType(typeof(NSObject))]
interface IALocationManagerDelegate
{
    // @optional -(void)indoorLocationManager:(IALocationManager * 
    _Nonnull)manager didUpdateLocations:(NSArray * _Nonnull)locations;
    [Export("indoorLocationManager:didUpdateLocations:")]
    void DidUpdateLocations(IALocationManager manager, IALocation[] locations);


    // @optional -(void)indoorLocationManager:(IALocationManager * 
    _Nonnull)manager didEnterRegion:(IARegion * _Nonnull)region;
    [Export("indoorLocationManager:didEnterRegion:")]
    void DidEnterRegion(IALocationManager manager, IARegion region);
}

// @interface IALocationManager : NSObject
[BaseType(typeof(NSObject))]
interface IALocationManager
{
     [Wrap("WeakDelegate")]
     [NullAllowed]
     IALocationManagerDelegate Delegate { get; set; }

     // @property (readwrite, nonatomic, weak) id<IALocationManagerDelegate> 
     _Nullable delegate;
     [NullAllowed, Export("delegate", ArgumentSemantic.Weak)]
     NSObject WeakDelegate { get; set; }
}

////ViewController --调用委托方法

[Export("indoorLocationManager:didUpdateLocations:")]
public void DidUpdateLocations(IALocationManager manager , IALocation[] locations)
{
    IALocation loc = locations[locations.Length - 1];
    if (mFloorPlan != null)
    {
        CoreGraphics.CGPoint cg = mFloorPlan.CoordinateToPoint(loc.Location.Coordinate);
        this.map.Center = cg;
    }
}

[Export("indoorLocationManager:didEnterRegion:")]
public  void DidEnterRegion(IALocationManager manager, IARegion region)
{
    if (region.Type != ia_region_type.FloorPlan)
        Console.WriteLine("Region Changed to {0} " + region.Identifier);
    else
    {
        FetchFloorPlan();
    }
}
4

1 回答 1

0

不要忘记将视图控制器分配给弱委托。

IALocationManager manager = new IALocationManager();
manager.WeakDelegate = this;
于 2017-10-03T09:36:00.710 回答