Xamarin表单-使用iOS本机库

Xamarin表单-使用iOS本机库,xamarin,Xamarin,我有使用Xamarin表单的移动应用程序。我还使用Objective-C编写了库something.framework,并使用XCode编写了示例项目 我需要在跨平台应用程序中使用此库。我在Xamarin.iOS项目中添加了对该库的本机引用。我使用依赖接口来管理按钮的操作,从Xamarin表单到Xamarin iOS。问题是VisualStudio并没有将对库的本机引用与类中的代码连接起来。Using指令并没有访问本机库,所以当我尝试使用来自库的方法时,会出现很多错误。我已经阅读了微软关于绑定本

我有使用Xamarin表单的移动应用程序。我还使用Objective-C编写了库something.framework,并使用XCode编写了示例项目

我需要在跨平台应用程序中使用此库。我在Xamarin.iOS项目中添加了对该库的本机引用。我使用依赖接口来管理按钮的操作,从Xamarin表单到Xamarin iOS。问题是VisualStudio并没有将对库的本机引用与类中的代码连接起来。Using指令并没有访问本机库,所以当我尝试使用来自库的方法时,会出现很多错误。我已经阅读了微软关于绑定本机库的说明,但没有找到答案

如何解决这个问题

以下是我使用Objective Sharpie时终端的日志:

Johns-Mac-mini:~ johnmiller$ sharpie bind
-output=InfColorPickerCustom -namespace=InfColorPickerCustom ~/Desktop/InfColorPicker/InfColorPicker/*.h -sdk=iphoneos12.1 Parsing 8 header files... In file included from /var/folders/_g/mb3qv73j16d_mdwzb8bf5hww0000gn/T/tmp765fc04f.h:2: /Users/johnmiller/Desktop/InfColorPicker/InfColorPicker/InfColorIndicatorView.h:19:1: warning: no 'assign', 'retain', or 'copy' attribute is specified - 'assign' is assumed [-Wobjc-property-no-attribute] @property (nonatomic) UIColor* color; ^ /Users/johnmiller/Desktop/InfColorPicker/InfColorPicker/InfColorIndicatorView.h:19:1: warning: default property attribute 'assign' not appropriate for non-GC object [-Wobjc-property-no-attribute] In file included from /var/folders/_g/mb3qv73j16d_mdwzb8bf5hww0000gn/T/tmp765fc04f.h:3: In file included from /Users/johnmiller/Desktop/InfColorPicker/InfColorPicker/InfColorPicker.h:60: /Users/johnmiller/Desktop/InfColorPicker/InfColorPicker/InfColorPickerController.h:28:1: warning: no 'assign', 'retain', or 'copy' attribute is specified - 'assign' is assumed [-Wobjc-property-no-attribute] @property (nonatomic) UIColor* sourceColor; ^ /Users/johnmiller/Desktop/InfColorPicker/InfColorPicker/InfColorPickerController.h:28:1: warning: default property attribute 'assign' not appropriate for non-GC object [-Wobjc-property-no-attribute] /Users/johnmiller/Desktop/InfColorPicker/InfColorPicker/InfColorPickerController.h:29:1: warning: no 'assign', 'retain', or 'copy' attribute is specified - 'assign' is assumed [-Wobjc-property-no-attribute] @property (nonatomic) UIColor* resultColor; ^ /Users/johnmiller/Desktop/InfColorPicker/InfColorPicker/InfColorPickerController.h:29:1: warning: default property attribute 'assign' not appropriate for non-GC object [-Wobjc-property-no-attribute]

Binding...   [write] ApiDefinitions.cs   [write] StructsAndEnums.cs

Binding Analysis:   Automated binding is complete, but there are a few APIs which have been flagged with [Verify] attributes. While the entire binding should be audited for best API design practices, look more closely at APIs with the following Verify attribute hints:

  ConstantsInterfaceAssociation (200 instances):
    There's no foolproof way to determine with which Objective-C interface an extern variable declaration may be associated. Instances of these are bound as [Field] properties in a partial interface into a nearby concrete interface to produce a more intuitive API,
    possibly eliminating the 'Constants' interface altogether.

  MethodToProperty (193 instances):
    An Objective-C method was bound as a C# property due to convention such as taking no parameters and returning a value (non-void return). Often methods like these should be bound as properties to surface a nicer API, but sometimes false-positives can occur and
    the binding should actually be a method.

  StronglyTypedNSArray (42 instances):
    A native NSArray* was bound as NSObject[]. It might be possible to more strongly type the array in the binding based on expectations set through API documentation (e.g. comments in the header file) or by examining the array contents through testing. For example,
     an NSArray* containing only NSNumber* instances can be bound as NSNumber[] instead of NSObject[].

  PlatformInvoke (3256 instances):
    In general P/Invoke bindings are not as correct or complete as Objective-C bindings (at least currently). You may need to fix up the library name (it defaults to '__Internal') and return/parameter types manually to conform to C calling conventionsfor the target
    platform. You may find you don't even want to expose the C API in your binding, but if you do, you'll probably also want to relocate the definition to a more appropriate class and expose a stronger type-safe wrapper. For P/Invoke guidance, see http://www.mono-
    project.com/docs/advanced/pinvoke/.

  InferredFromMemberPrefix (29 instances):
    The name of this originally anonymous declaration was taken from a common prefix of its members.

  Once you have verified a Verify attribute, you should remove it from the binding source code. The presence of Verify attributes intentionally cause build failures.
     For more information about the Verify attribute hints above, consult the Objective Sharpie documentation by running 'sharpie docs' or visiting the following URL:

    http://xmn.io/sharpie-docs 6 warnings generated.

Done. Johns-Mac-mini:~ johnmiller$

我已经解决了。使用客观夏比时需要使用范围。简单添加-scope~/Desktop/InfColorPicker/InfColorPicker。然后Sharpie正在生成小文件

您是否为ObjC框架创建了C绑定?只需向框架添加本机引用就可以创建绑定,您必须手动创建它们或使用Sharpie引导这些绑定。以防万一,如果Cocoapod中提供了该框架,那么就更容易了。您是否参考过本文档?显示一些日志信息或图像会很有帮助。我使用Sharpie从终端生成了ApiDefinition.cs和StructsAndEnums.cs,但它们有60000多行和11000多个错误。如何避免这些问题?@YoungEddie Okey,首先需要分析出现的错误日志,然后才能找到原因。