0

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();
    }
}
ColeX
  • 14,062
  • 5
  • 43
  • 240
nikheel
  • 3
  • 2
  • 1.Did the binding project build successfully? 2. It seems like you use weakDelegate , did you set it? – ColeX Oct 03 '17 at 02:36
  • @ColeXia Yes binding project is building fine with no errors or issues. I am using weak Delegate and it is set weak in API definition. – nikheel Oct 03 '17 at 06:12
  • Did you assign the current viewcontroller to weak delegate, `IALocationManager.WeakDelegate = this` – ColeX Oct 03 '17 at 06:16
  • @ColeXia Perfect !! Thanks a lot. It worked. – nikheel Oct 03 '17 at 07:47

1 Answers1

0

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

IALocationManager manager = new IALocationManager();
manager.WeakDelegate = this;
ColeX
  • 14,062
  • 5
  • 43
  • 240