我想用xamarin绑定一个objective c库(为了使用电缆)。我是xamarin平台的新手,谁能帮我在Xamarin绑定项目中将下面的.h文件转换为"ApiDefinition.cs“。
#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发布于 2015-07-04 06:12:52
我不能为您编写它,但下面的示例是一般模式,您可以在下面链接的指南中了解更多信息。您的关键挑战之一将是确保触发委托上的回调。要映射这一点,请查看“绑定协议”部分。
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();
}若要完成此绑定,应将本机库添加到项目中。为此,可以将本机库添加到项目中,方法是将本机库从Finder拖放到解决方案资源管理器中的项目上,或者右击项目并选择“添加”>“添加文件”以选择本机库。按照惯例,本机库以单词"lib“开头,以扩展名".a”结束。执行此操作时,Xamarin Studio将添加两个文件:.a文件和一个自动填充的C#文件,其中包含有关本机库所包含内容的信息:
您最终将得到一个如下所示的文件(libLibraryName.linkwith.cs):
using System;
using MonoTouch.ObjCRuntime;
[assembly: LinkWith ("libLibraryName.a", SmartLink = true, ForceLoad = true)]发布于 2015-08-13 07:22:12
使用Objective-Sharpie。它将为你完成最初的大量工作,你只需要填补空白……
https://stackoverflow.com/questions/30118083
复制相似问题