bindingxamarin.iosprotocolsobjective-sharpiexamarin.ios-binding

After binding using Objective Sharpie Protocol Methods are not getting invoked in xamarin.iOS


I have few issues with Binding using Objective sharpie.I am binding IndoorAtlas iOS native sdk with Xamarin.ios.

Issue is while Implementing Protocols methods as those are not getting invoked. Do we need to handle it in special way?

I am attaching API defination file and Implementation file.

// @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 --Calling delegate methods

[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();
    }
}

Solution

  • Don't forget to assign the viewcontroller to the weak delegate.

    IALocationManager manager = new IALocationManager();
    manager.WeakDelegate = this;