diff --git a/src/NearbyInteraction/Enums.cs b/src/NearbyInteraction/Enums.cs index a61d4cc904ba..5bd9f7314098 100644 --- a/src/NearbyInteraction/Enums.cs +++ b/src/NearbyInteraction/Enums.cs @@ -14,6 +14,7 @@ namespace NearbyInteraction { [NoWatch, NoTV, NoMac, iOS (14,0)] + [ErrorDomain ("NIErrorDomain")] [Native] public enum NIErrorCode : long { diff --git a/src/NearbyInteraction/NINearbyObject.cs b/src/NearbyInteraction/NINearbyObject.cs new file mode 100644 index 000000000000..50a1de3d6fb8 --- /dev/null +++ b/src/NearbyInteraction/NINearbyObject.cs @@ -0,0 +1,41 @@ +// +// NearbyInteraction manual bindings +// +// Authors: +// Whitney Schmidt +// +// Copyright 2020 Microsoft Inc. +// + +using System; +using System.Runtime.InteropServices; + +using CoreFoundation; +using Foundation; +using ObjCRuntime; +using Vector3 = global::OpenTK.Vector3; + +#if __IOS__ +namespace NearbyInteraction { + partial class NINearbyObject + { + static Vector3? _DirectionNotAvailable; + + // TODO: https://github.com/xamarin/maccore/issues/2274 + // We do not have generator support to trampoline Vector3 -> vector_float3 for Fields + [Field ("NINearbyObjectDirectionNotAvailable", "NearbyInteraction")] + public static Vector3 DirectionNotAvailable { + get { + if (_DirectionNotAvailable == null) { + unsafe { + Vector3 *pointer = (Vector3 *) Dlfcn.GetIndirect (Libraries.NearbyInteraction.Handle, "NINearbyObjectDirectionNotAvailable"); + _DirectionNotAvailable = *pointer; + } + } + return (Vector3)_DirectionNotAvailable; + } + } + } + +} +#endif //__IOS__ diff --git a/src/frameworks.sources b/src/frameworks.sources index 1ac844bba055..7f63ca2703b9 100644 --- a/src/frameworks.sources +++ b/src/frameworks.sources @@ -1202,6 +1202,9 @@ NETWORK_SOURCES = \ NEARBYINTERACTION_API_SOURCES = \ NearbyInteraction/Enums.cs \ +NEARBYINTERACTION_SOURCES = \ + NearbyInteraction/NINearbyObject.cs \ + # NetworkExtension NETWORKEXTENSION_API_SOURCES = \ diff --git a/src/nearbyinteraction.cs b/src/nearbyinteraction.cs index 1c094dff174c..501c3f778ea6 100644 --- a/src/nearbyinteraction.cs +++ b/src/nearbyinteraction.cs @@ -15,14 +15,6 @@ namespace NearbyInteraction { - [NoWatch, NoTV, NoMac, iOS (14, 0)] - [Static] - interface NIErrorDomain - { - [Field ("NIErrorDomain")] - NSString Domain { get; } - } - [NoWatch, NoTV, NoMac, iOS (14,0)] [BaseType (typeof (NSObject))] [DisableDefaultCtor] @@ -64,16 +56,6 @@ Vector3 Direction { [Field ("NINearbyObjectDistanceNotAvailable")] float DistanceNotAvailable { get; } - - // TODO: https://github.com/xamarin/maccore/issues/2274 - // We do not have generator support to trampoline Vector3 -> vector_float3 for Fields - // There is support for Vector3 -> vector_float3 for properties - // error BI1014: bgen: Unsupported type for Fields: global::OpenTK.Vector3 for 'NearbyInteraction.NINearbyObjectDistance DirectionNotAvailable'. - // extern simd_float3 NINearbyObjectDirectionNotAvailable __attribute__((availability(ios, introduced=14.0))) __attribute__((availability(macos, unavailable))) __attribute__((availability(watchos, unavailable))) __attribute__((availability(tvos, unavailable))) __attribute__((visibility("default"))) __attribute__((availability(swift, unavailable))); - // [Unavailable (PlatformName.Swift)] - // [NoWatch, NoTV, NoMac, iOS (14, 0)] - // [Field ("NINearbyObjectDirectionNotAvailable")] - // [unsupported ExtVector: float __attribute__((ext_vector_type(3)))] NINearbyObjectDirectionNotAvailable { get; } } [NoWatch, NoTV, NoMac, iOS (14,0)] diff --git a/tests/monotouch-test/NearbyInteraction/NINearbyObjectTest.cs b/tests/monotouch-test/NearbyInteraction/NINearbyObjectTest.cs new file mode 100644 index 000000000000..151ad841897a --- /dev/null +++ b/tests/monotouch-test/NearbyInteraction/NINearbyObjectTest.cs @@ -0,0 +1,36 @@ +// Copyright 2020 Microsoft Corp. + +#if __IOS__ + +using System; +using Foundation; +using ObjCRuntime; +using NearbyInteraction; +using NUnit.Framework; +using OpenTK; + +namespace MonoTouchFixtures.NearbyInteraction { + + [TestFixture] + [Preserve (AllMembers = true)] + public class NINearbyObjectTest { + + [Test] + public void DirectionNotAvailable () + { + TestRuntime.AssertXcodeVersion (12, 0); + + Vector3 vect = NINearbyObject.DirectionNotAvailable; + + unsafe { + Vector3* v = &vect; + byte* ptr = (byte*) v; + byte zero = 0; + for (var i = 0; i < sizeof (Vector3); i++) + Assert.That (ptr [i], Is.EqualTo (zero), $"Position {i}"); + } + } + } +} + +#endif // __IOS__ diff --git a/tests/monotouch-test/monotouch-test.csproj b/tests/monotouch-test/monotouch-test.csproj index 505aa130b919..115b8f61f451 100644 --- a/tests/monotouch-test/monotouch-test.csproj +++ b/tests/monotouch-test/monotouch-test.csproj @@ -285,6 +285,7 @@ + diff --git a/tests/xtro-sharpie/iOS-NearbyInteraction.ignore b/tests/xtro-sharpie/iOS-NearbyInteraction.ignore deleted file mode 100644 index 28d073d4579f..000000000000 --- a/tests/xtro-sharpie/iOS-NearbyInteraction.ignore +++ /dev/null @@ -1,3 +0,0 @@ -## TODO: https://github.com/xamarin/maccore/issues/2274 -## We do not have generator support to trampoline Vector3 -> vector_float3 for Fields -!missing-field! NINearbyObjectDirectionNotAvailable not bound