i want bind objective c library (for using cable) in xamarin. new xamarin platform, can me convert below .h file "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; /* protocol), describes main interface cable socket manager layer. use, call factory method below [cablemanager sharedinstance] */ @protocol cablemanagerprotocol <nsobject> // set delegate cable connect callbacks -(void)setdelegate:(id < cablemanagerdelegate >) delegate; -(bool)iscableconnected; -(nsstring *)getaccessoryfirmwareversion; @end @protocol cablemanagerdelegate <nsobject> //cable connected - (void) cableconnected:(nsstring *)protocol; // cable disconnected and/or application moved background - (void) cabledisconnected; @end @interface cablemanager : nsobject + (id < cablemanagerprotocol >)sharedinstance; @end
can't write you, sample below general pattern can learn more in guide linked below. 1 of key challenges going making sure callback on delegate fires. map this, check out "binding protocols" 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 binding, should add native library project. can adding native library project, either dragging , dropping native library finder onto project in solution explorer, or right-clicking project , choosing add > add files select native library. native libraries convention start word "lib" , end extension ".a". when this, xamarin studio add 2 files: .a file , automatically populated c# file contains information native library contains:
you end file (liblibraryname.linkwith.cs):
using system; using monotouch.objcruntime; [assembly: linkwith ("liblibraryname.a", smartlink = true, forceload = true)]
Comments
Post a Comment