1

我在演练中仔细遵循了每个步骤:绑定 iOS Objective-C 库

TestBindings项目的构建结果是成功的。

但是,我得到了空的命名空间引用。

空命名空间

我的开发环境设置是:

  1. 视窗 10 专业版 1909
  2. Visual Studio 2019 专业版 16.6.0
  3. macOS Catalina 10.15.5
  4. 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
    {
    }
}

结构体.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

libTestBindings.a 属性

苹果系统

Xcode 项目设置 Xcode 项目设置

生成文件 生成文件

文件夹 文件夹

4

1 回答 1

1

Native Binding 项目编译没有方法或类的库

修复了问题。问题是绑定项目与 Xamarin.iOS 项目位于同一解决方案中,因此它没有正确引用该项目。从解决方案中删除了绑定项目,然后添加了绑定项目 DLL 作为参考,现在它可以正确地看到命名空间和方法。我将解决您提到的其他问题,例如所需的框架。谢谢你的帮助!这个问题可以关闭。

此页面帮助:

https://forums.xamarin.com/discussion/81795/ios-obj-c-binding-cant-see-namespace

于 2020-05-26T09:38:24.207 回答