Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Binding Objective-C Protocols

$
0
0

I am in the process of writing bindings for the LiveSDK iOS library for Xamarin and I've hit another snag.

I was following some examples/using Objective Sharpie to writing my bindings for the library and thought I had set the up correctly but when I went to use the binding using an example from the LiveSDK documentation I realised that the protocols weren't converted into interfaces but classes instead.

First part of the tutorial asks you to set up a view controller like this:

@interface ViewController : UIViewController<LiveAuthDelegate, LiveOperationDelegate, LiveDownloadOperationDelegate, LiveUploadOperationDelegate>

Which would likely end up being like this in C#/Xamarin

public partial class ViewController : UIViewController, ILiveAuthDelegate, ILiveOperationDelegate, ILiveDownloadOperationDelegate, ILiveUploadOperationDelegate

I then started following the documentation here to try implement the protocols to have interfaces but I'm a little confused by what to do.

An example of one of the Objective-C header files I'm trying to bind to is as follows:

@protocol LiveAuthDelegate <NSObject>

- (void) authCompleted: (LiveConnectSessionStatus) status
               session: (LiveConnectSession *) session
             userState: (id) userState;

@optional
- (void) authFailed: (NSError *) error
         userState: (id)userState;

@‌end

The C# binding code I have for that at present is as follows:

    [BaseType(typeof(NSObject))]
    [Model, Protocol]
    public interface LiveAuthDelegate {

        [Export ("authCompleted:session:userState:")]
    void AuthCompleted(LiveConnectSessionStatus status, LiveConnectSession session, NSObject userState);

        [Export ("authFailed:userState:")]
        void AuthFailed(NSError error, NSObject userState);
    } 

This does seem to create an interface in the DLL but I'm unsure if it's correct or how to actually use it as an interface to the view controller class. The DLL code looks like this for the interface atm:

    [Protocol(Name = "LiveAuthDelegate", WrapperType = typeof(LiveAuthDelegateWrapper))]
    public interface ILiveAuthDelegate : INativeObject, IDisposable
    {
    }

How should I correctly bind the protocol interfaces in this instance?

Any help would be appreciated.

Regards Hobsie


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>