Xamarin required object c library

I want to link the c object library (for cable use) in xamarin. I am new to xamarin platform, can anyone help me convert the .h file to "ApiDefinition.cs" in Xamarin binding project.

#import <UIKit/UIKit.h>

#ifndef CABLE_

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
@protocol CableManagerDelegate;

/*

    This protocol), describes the main interface to the Cable Socket Manager layer.

    To use, call factory method below [CableManager sharedInstance]

 */
@protocol CableManagerProtocol <NSObject>
// set delegate for cable connect callbacks
-(void)setDelegate:(id < CableManagerDelegate >) delegate;

-(BOOL)isCableConnected;

-(NSString *)getAccessoryFirmwareVersion;

@end

@protocol CableManagerDelegate <NSObject>

//Cable was connected
- (void) cableConnected:(NSString *)protocol;

// Cable was disconnected and/or application moved to background
- (void) cableDisconnected;
@end


@interface CableManager : NSObject

+ (id < CableManagerProtocol >)sharedInstance;

@end

      

+3


source to share


2 answers


There is no way to write it down for you, but the example below is a general pattern that you can learn more about in the tutorial below. One of your main tasks is to make sure the callback is on delegate lights. To create a map, see the Protocol Binding section.

http://developer.xamarin.com/guides/ios/advanced_topics/binding_objective-c/binding_objc_libs/

ApiDefinition.cs

using MonoTouch.ObjCRuntime;
using MonoTouch.Foundation;
using System;

namespace MyNamespace
{
  [BaseType (typeof (NSObject))]
  interface MyObjCWrapper
  {
    [Export("initWithArg1:arg2:arg3:")]
    void Constructor(string first, string second, string third);

    [Export("mySelectorTaking1arg:")] // note colon, takes 1 arg
    void DoSomethingWith1Arg(string filePath);

    [Export("getSomething")] // note no colon, takes 0 args
    int GetSomething();
}

      



To complete this binding, you must add your own library to the project. You can do this by adding your own library to the project, either by dragging the native library from Finder onto the project in the solution explorer, or by right-clicking the project and choosing Add> Add Files to select your own library. Native libraries by convention begin with the word "lib" and end with the extension ".a". When you do, Xamarin Studio will add two files: an .a file and an auto-filled C # file containing information about what the built-in library contains:

You end up with a file like this (libLibraryName.linkwith.cs):

using System;
using MonoTouch.ObjCRuntime;

[assembly: LinkWith ("libLibraryName.a", SmartLink = true, ForceLoad = true)]

      

+2


source


Use Objective-Sharpie . It will do the bulk of the work for you and you just need to fill in the blanks ...



+1


source







All Articles