Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NearbyInteraction][Xcode12] Add manual binding for NINearbyObjectDirectionNotAvailable #9346

Merged
merged 12 commits into from
Aug 12, 2020
1 change: 1 addition & 0 deletions src/NearbyInteraction/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace NearbyInteraction {

[NoWatch, NoTV, NoMac, iOS (14,0)]
[ErrorDomain ("NIErrorDomain")]
[Native]
public enum NIErrorCode : long
{
Expand Down
41 changes: 41 additions & 0 deletions src/NearbyInteraction/NINearbyObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// NearbyInteraction manual bindings
//
// Authors:
// Whitney Schmidt <[email protected]>
//
// Copyright 2020 Microsoft Inc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: it's not Inc. it's Corp. ;-)

//

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__
3 changes: 3 additions & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,9 @@ NETWORK_SOURCES = \
NEARBYINTERACTION_API_SOURCES = \
NearbyInteraction/Enums.cs \

NEARBYINTERACTION_SOURCES = \
NearbyInteraction/NINearbyObject.cs \

# NetworkExtension

NETWORKEXTENSION_API_SOURCES = \
Expand Down
18 changes: 0 additions & 18 deletions src/nearbyinteraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)]
Expand Down
36 changes: 36 additions & 0 deletions tests/monotouch-test/NearbyInteraction/NINearbyObjectTest.cs
Original file line number Diff line number Diff line change
@@ -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__
1 change: 1 addition & 0 deletions tests/monotouch-test/monotouch-test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@
<Folder Include="Compression\" />
<Folder Include="BackgroundTasks\" />
<Folder Include="WebKit\" />
<Folder Include="NearbyInteraction\" />
</ItemGroup>
<ItemGroup>
<Content Include="AudioToolbox\1.caf" />
Expand Down
3 changes: 0 additions & 3 deletions tests/xtro-sharpie/iOS-NearbyInteraction.ignore

This file was deleted.