Xamarin.iOS 绑定 iOS Objective-C 库导致命名空间为空
Xamarin.iOS Binding an iOS Objective-C Library resulted in empty namespace
我仔细按照Walkthrough: Binding an iOS Objective-C Library
中的每个步骤
TestBindings项目的构建结果是成功.
但是,我得到了空的命名空间引用。
我的开发环境设置是:
- Windows 10 专业版 1909
- Visual Studio2019专业版16.6.0
- macOS 卡特琳娜 10.15.5
- XCode版本 11.4.1
项目结构是:
每个源代码是:
ApiDefinition.cs
using CoreGraphics;
using Foundation;
using ObjCRuntime;
using UIKit;
namespace TestBindings
{
// @interface InfColorBarView : UIView
[BaseType(typeof(UIView))]
interface InfColorBarView
{
}
// @interface InfColorBarPicker : UIControl
[BaseType(typeof(UIControl))]
interface InfColorBarPicker
{
// @property (nonatomic) float value;
[Export("value")]
float Value { get; set; }
}
// @interface InfColorIndicatorView : UIView
[BaseType(typeof(UIView))]
interface InfColorIndicatorView
{
// @property (nonatomic) UIColor * color;
[Export("color", ArgumentSemantic.Assign)]
UIColor Color { get; set; }
}
// @interface InfColorPickerController : UIViewController
[BaseType(typeof(UIViewController))]
interface InfColorPickerController
{
// +(InfColorPickerController *)colorPickerViewController;
[Static]
[Export("colorPickerViewController")]
// [Verify(MethodToProperty)]
InfColorPickerController ColorPickerViewController { get; }
// +(CGSize)idealSizeForViewInPopover;
[Static]
[Export("idealSizeForViewInPopover")]
// [Verify(MethodToProperty)]
CGSize IdealSizeForViewInPopover { get; }
// -(void)presentModallyOverViewController:(UIViewController *)controller;
[Export("presentModallyOverViewController:")]
void PresentModallyOverViewController(UIViewController controller);
// @property (nonatomic) UIColor * sourceColor;
[Export("sourceColor", ArgumentSemantic.Assign)]
UIColor SourceColor { get; set; }
// @property (nonatomic) UIColor * resultColor;
[Export("resultColor", ArgumentSemantic.Assign)]
UIColor ResultColor { get; set; }
[Wrap("WeakDelegate")]
InfColorPickerControllerDelegate Delegate { get; set; }
// @property (nonatomic, weak) id<InfColorPickerControllerDelegate> delegate;
[NullAllowed, Export("delegate", ArgumentSemantic.Weak)]
NSObject WeakDelegate { get; set; }
}
// @protocol InfColorPickerControllerDelegate
[BaseType(typeof(NSObject))]
[Model]
interface InfColorPickerControllerDelegate
{
// @optional -(void)colorPickerControllerDidFinish:(InfColorPickerController *)controller;
[Export("colorPickerControllerDidFinish:")]
void ColorPickerControllerDidFinish(InfColorPickerController controller);
// @optional -(void)colorPickerControllerDidChangeColor:(InfColorPickerController *)controller;
[Export("colorPickerControllerDidChangeColor:")]
void ColorPickerControllerDidChangeColor(InfColorPickerController controller);
}
// @interface InfColorPickerNavigationController : UINavigationController
[BaseType(typeof(UINavigationController))]
interface InfColorPickerNavigationController
{
}
// @interface InfColorSquareView : UIImageView
[BaseType(typeof(UIImageView))]
interface InfColorSquareView
{
// @property (nonatomic) float hue;
[Export("hue")]
float Hue { get; set; }
}
// @interface InfColorSquarePicker : UIControl
[BaseType(typeof(UIControl))]
interface InfColorSquarePicker
{
// @property (nonatomic) float hue;
[Export("hue")]
float Hue { get; set; }
// @property (nonatomic) CGPoint value;
[Export("value", ArgumentSemantic.Assign)]
CGPoint Value { get; set; }
}
// @interface InfSourceColorView : UIControl
[BaseType(typeof(UIControl))]
interface InfSourceColorView
{
// @property (nonatomic) BOOL trackingInside;
[Export("trackingInside")]
bool TrackingInside { get; set; }
}
// @interface TestBindings : NSObject
[BaseType(typeof(NSObject))]
interface TestBindings
{
}
}
Structs.cs
using System;
using System.Runtime.InteropServices;
using CoreGraphics;
namespace TestBindings
{
static class CFunctions
{
// extern float pin (float minValue, float value, float maxValue);
[DllImport("__Internal")]
// [Verify(PlatformInvoke)]
static extern float pin(float minValue, float value, float maxValue);
// extern void HSVtoRGB (float h, float s, float v, float *r, float *g, float *b);
[DllImport("__Internal")]
// [Verify(PlatformInvoke)]
static extern unsafe void HSVtoRGB(float h, float s, float v, float* r, float* g, float* b);
// extern void RGBToHSV (float r, float g, float b, float *h, float *s, float *v, BOOL preserveHS);
[DllImport("__Internal")]
// [Verify(PlatformInvoke)]
static extern unsafe void RGBToHSV(float r, float g, float b, float* h, float* s, float* v, bool preserveHS);
// extern CGImageRef createSaturationBrightnessSquareContentImageWithHue (float hue);
[DllImport("__Internal")]
// [Verify(PlatformInvoke)]
static extern unsafe CGImage createSaturationBrightnessSquareContentImageWithHue(float hue);
// extern CGImageRef createHSVBarContentImage (InfComponentIndex barComponentIndex, float *hsv);
[DllImport("__Internal")]
// [Verify(PlatformInvoke)]
static extern unsafe CGImage createHSVBarContentImage(InfComponentIndex barComponentIndex, float[] hsv);
}
public enum InfComponentIndex : uint
{
Hue = 0,
Saturation = 1,
Brightness = 2
}
}
libTestBindings.linkwith.cs
using System;
using ObjCRuntime;
[assembly: LinkWith ("libTestBindings.a", LinkTarget.ArmV7, SmartLink = true, ForceLoad = true)]
libTestBindings.a
MAC OS
Xcode 项目设置
生成文件
文件夹
Native Binding Project Compiles Library With No Methods Or Classes
Fixed the problem. The issue was that the Binding Project was in the same solution as the Xamarin.iOS project so it was not referencing the project correctly. Removed the binding project from the solution, then added the binding project DLL as a reference and now it properly sees the namespace and the methods. I will fix the other issues you mentioned like required frameworks. Thanks for your help! This issue can be closed.
This page helped:
https://forums.xamarin.com/discussion/81795/ios-obj-c-binding-cant-see-namespace
我仔细按照Walkthrough: Binding an iOS Objective-C Library
中的每个步骤TestBindings项目的构建结果是成功.
但是,我得到了空的命名空间引用。
我的开发环境设置是:
- Windows 10 专业版 1909
- Visual Studio2019专业版16.6.0
- macOS 卡特琳娜 10.15.5
- XCode版本 11.4.1
项目结构是:
每个源代码是:
ApiDefinition.cs
using CoreGraphics;
using Foundation;
using ObjCRuntime;
using UIKit;
namespace TestBindings
{
// @interface InfColorBarView : UIView
[BaseType(typeof(UIView))]
interface InfColorBarView
{
}
// @interface InfColorBarPicker : UIControl
[BaseType(typeof(UIControl))]
interface InfColorBarPicker
{
// @property (nonatomic) float value;
[Export("value")]
float Value { get; set; }
}
// @interface InfColorIndicatorView : UIView
[BaseType(typeof(UIView))]
interface InfColorIndicatorView
{
// @property (nonatomic) UIColor * color;
[Export("color", ArgumentSemantic.Assign)]
UIColor Color { get; set; }
}
// @interface InfColorPickerController : UIViewController
[BaseType(typeof(UIViewController))]
interface InfColorPickerController
{
// +(InfColorPickerController *)colorPickerViewController;
[Static]
[Export("colorPickerViewController")]
// [Verify(MethodToProperty)]
InfColorPickerController ColorPickerViewController { get; }
// +(CGSize)idealSizeForViewInPopover;
[Static]
[Export("idealSizeForViewInPopover")]
// [Verify(MethodToProperty)]
CGSize IdealSizeForViewInPopover { get; }
// -(void)presentModallyOverViewController:(UIViewController *)controller;
[Export("presentModallyOverViewController:")]
void PresentModallyOverViewController(UIViewController controller);
// @property (nonatomic) UIColor * sourceColor;
[Export("sourceColor", ArgumentSemantic.Assign)]
UIColor SourceColor { get; set; }
// @property (nonatomic) UIColor * resultColor;
[Export("resultColor", ArgumentSemantic.Assign)]
UIColor ResultColor { get; set; }
[Wrap("WeakDelegate")]
InfColorPickerControllerDelegate Delegate { get; set; }
// @property (nonatomic, weak) id<InfColorPickerControllerDelegate> delegate;
[NullAllowed, Export("delegate", ArgumentSemantic.Weak)]
NSObject WeakDelegate { get; set; }
}
// @protocol InfColorPickerControllerDelegate
[BaseType(typeof(NSObject))]
[Model]
interface InfColorPickerControllerDelegate
{
// @optional -(void)colorPickerControllerDidFinish:(InfColorPickerController *)controller;
[Export("colorPickerControllerDidFinish:")]
void ColorPickerControllerDidFinish(InfColorPickerController controller);
// @optional -(void)colorPickerControllerDidChangeColor:(InfColorPickerController *)controller;
[Export("colorPickerControllerDidChangeColor:")]
void ColorPickerControllerDidChangeColor(InfColorPickerController controller);
}
// @interface InfColorPickerNavigationController : UINavigationController
[BaseType(typeof(UINavigationController))]
interface InfColorPickerNavigationController
{
}
// @interface InfColorSquareView : UIImageView
[BaseType(typeof(UIImageView))]
interface InfColorSquareView
{
// @property (nonatomic) float hue;
[Export("hue")]
float Hue { get; set; }
}
// @interface InfColorSquarePicker : UIControl
[BaseType(typeof(UIControl))]
interface InfColorSquarePicker
{
// @property (nonatomic) float hue;
[Export("hue")]
float Hue { get; set; }
// @property (nonatomic) CGPoint value;
[Export("value", ArgumentSemantic.Assign)]
CGPoint Value { get; set; }
}
// @interface InfSourceColorView : UIControl
[BaseType(typeof(UIControl))]
interface InfSourceColorView
{
// @property (nonatomic) BOOL trackingInside;
[Export("trackingInside")]
bool TrackingInside { get; set; }
}
// @interface TestBindings : NSObject
[BaseType(typeof(NSObject))]
interface TestBindings
{
}
}
Structs.cs
using System;
using System.Runtime.InteropServices;
using CoreGraphics;
namespace TestBindings
{
static class CFunctions
{
// extern float pin (float minValue, float value, float maxValue);
[DllImport("__Internal")]
// [Verify(PlatformInvoke)]
static extern float pin(float minValue, float value, float maxValue);
// extern void HSVtoRGB (float h, float s, float v, float *r, float *g, float *b);
[DllImport("__Internal")]
// [Verify(PlatformInvoke)]
static extern unsafe void HSVtoRGB(float h, float s, float v, float* r, float* g, float* b);
// extern void RGBToHSV (float r, float g, float b, float *h, float *s, float *v, BOOL preserveHS);
[DllImport("__Internal")]
// [Verify(PlatformInvoke)]
static extern unsafe void RGBToHSV(float r, float g, float b, float* h, float* s, float* v, bool preserveHS);
// extern CGImageRef createSaturationBrightnessSquareContentImageWithHue (float hue);
[DllImport("__Internal")]
// [Verify(PlatformInvoke)]
static extern unsafe CGImage createSaturationBrightnessSquareContentImageWithHue(float hue);
// extern CGImageRef createHSVBarContentImage (InfComponentIndex barComponentIndex, float *hsv);
[DllImport("__Internal")]
// [Verify(PlatformInvoke)]
static extern unsafe CGImage createHSVBarContentImage(InfComponentIndex barComponentIndex, float[] hsv);
}
public enum InfComponentIndex : uint
{
Hue = 0,
Saturation = 1,
Brightness = 2
}
}
libTestBindings.linkwith.cs
using System;
using ObjCRuntime;
[assembly: LinkWith ("libTestBindings.a", LinkTarget.ArmV7, SmartLink = true, ForceLoad = true)]
libTestBindings.a
MAC OS
Xcode 项目设置
生成文件
文件夹
Native Binding Project Compiles Library With No Methods Or Classes
Fixed the problem. The issue was that the Binding Project was in the same solution as the Xamarin.iOS project so it was not referencing the project correctly. Removed the binding project from the solution, then added the binding project DLL as a reference and now it properly sees the namespace and the methods. I will fix the other issues you mentioned like required frameworks. Thanks for your help! This issue can be closed.
This page helped:
https://forums.xamarin.com/discussion/81795/ios-obj-c-binding-cant-see-namespace