diff --git a/src/Constants.iOS.cs.in b/src/Constants.iOS.cs.in index c74e843ea2..8a5a151cb3 100644 --- a/src/Constants.iOS.cs.in +++ b/src/Constants.iOS.cs.in @@ -149,6 +149,7 @@ namespace ObjCRuntime { public const string AppClipLibrary = "/System/Library/Frameworks/AppClip.framework/AppClip"; public const string MediaSetupLibrary = "/System/Library/Frameworks/MediaSetup.framework/MediaSetup"; public const string MLComputeLibrary = "/System/Library/Frameworks/MLCompute.framework/MLCompute"; + public const string NearbyInteractionLibrary = "/System/Library/Frameworks/NearbyInteraction.framework/NearbyInteraction"; public const string SensorKitLibrary = "/System/Library/Frameworks/SensorKit.framework/SensorKit"; public const string UniformTypeIdentifiersLibrary = "/System/Library/Frameworks/UniformTypeIdentifiers.framework/UniformTypeIdentifiers"; } diff --git a/src/Constants.mac.cs.in b/src/Constants.mac.cs.in index 702602c18b..5f13efe6dc 100644 --- a/src/Constants.mac.cs.in +++ b/src/Constants.mac.cs.in @@ -175,6 +175,7 @@ namespace ObjCRuntime { public const string AccessibilityLibrary = "/System/Library/Frameworks/Accessibility.framework/Accessibility"; public const string ClassKitLibrary = "/System/Library/Frameworks/ClassKit.framework/ClassKit"; public const string MLComputeLibrary = "/System/Library/Frameworks/MLCompute.framework/MLCompute"; + public const string NearbyInteractionLibrary = "/System/Library/Frameworks/NearbyInteraction.framework/NearbyInteraction"; public const string ReplayKitLibrary = "/System/Library/Frameworks/ReplayKit.framework/ReplayKit"; public const string UniformTypeIdentifiersLibrary = "/System/Library/Frameworks/UniformTypeIdentifiers.framework/UniformTypeIdentifiers"; public const string UserNotificationsUILibrary = "/System/Library/Frameworks/UserNotificationsUI.framework/UserNotificationsUI"; diff --git a/src/NearbyInteraction/Enums.cs b/src/NearbyInteraction/Enums.cs new file mode 100644 index 0000000000..a61d4cc904 --- /dev/null +++ b/src/NearbyInteraction/Enums.cs @@ -0,0 +1,35 @@ +// +// NearbyInteraction enums +// +// Authors: +// Whitney Schmidt +// +// Copyright 2020 Microsoft Inc. +// + +using ObjCRuntime; +using Foundation; +using System; + +namespace NearbyInteraction { + + [NoWatch, NoTV, NoMac, iOS (14,0)] + [Native] + public enum NIErrorCode : long + { + UnsupportedPlatform = -5889, + InvalidConfiguration = -5888, + SessionFailed = -5887, + ResourceUsageTimeout = -5886, + ActiveSessionsLimitExceeded = -5885, + UserDidNotAllow = -5884, + } + + [NoWatch, NoTV, NoMac, iOS (14,0)] + [Native] + public enum NINearbyObjectRemovalReason : long + { + Timeout, + PeerEnded, + } +} diff --git a/src/frameworks.sources b/src/frameworks.sources index 282dcb89d5..1ac844bba0 100644 --- a/src/frameworks.sources +++ b/src/frameworks.sources @@ -1197,7 +1197,11 @@ NETWORK_SOURCES = \ Network/NWWebSocketOptions.cs \ Network/NWWebSocketRequest.cs \ Network/NWWebSocketResponse.cs \ - + +# NearbyInteraction +NEARBYINTERACTION_API_SOURCES = \ + NearbyInteraction/Enums.cs \ + # NetworkExtension NETWORKEXTENSION_API_SOURCES = \ @@ -1881,6 +1885,7 @@ MAC_FRAMEWORKS = \ MobileCoreServices \ ModelIO \ MultipeerConnectivity \ + NearbyInteraction \ NetworkExtension \ NotificationCenter \ OpenGL \ @@ -1981,6 +1986,7 @@ IOS_FRAMEWORKS = \ MobileCoreServices \ ModelIO \ MultipeerConnectivity \ + NearbyInteraction \ NetworkExtension \ NewsstandKit \ NotificationCenter \ diff --git a/src/nearbyinteraction.cs b/src/nearbyinteraction.cs new file mode 100644 index 0000000000..1c094dff17 --- /dev/null +++ b/src/nearbyinteraction.cs @@ -0,0 +1,136 @@ +// +// NearbyInteraction bindings +// +// Authors: +// Whitney Schmidt +// +// Copyright 2020 Microsoft Inc. +// + +using ObjCRuntime; +using Foundation; +using CoreFoundation; +using System; +using Vector3 = global::OpenTK.Vector3; + +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] + interface NIConfiguration : NSCopying, NSSecureCoding {} + + [NoWatch, NoTV, NoMac, iOS (14,0)] + [BaseType (typeof (NSObject))] + [DisableDefaultCtor] + interface NIDiscoveryToken : NSCopying, NSSecureCoding {} + + [NoWatch, NoTV, NoMac, iOS (14,0)] + [BaseType (typeof (NIConfiguration))] + [DisableDefaultCtor] + interface NINearbyPeerConfiguration + { + [Export ("peerDiscoveryToken", ArgumentSemantic.Copy)] + NIDiscoveryToken PeerDiscoveryToken { get; } + + [Export ("initWithPeerToken:")] + IntPtr Constructor (NIDiscoveryToken peerToken); + } + + [NoWatch, NoTV, NoMac, iOS (14,0)] + [BaseType (typeof (NSObject))] + [DisableDefaultCtor] + partial interface NINearbyObject : NSCopying, NSSecureCoding + { + [Export ("discoveryToken", ArgumentSemantic.Copy)] + NIDiscoveryToken DiscoveryToken { get; } + + [Export ("distance")] + float Distance { get; } + + [Export ("direction")] + Vector3 Direction { + [MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")] + get; + } + + [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)] + [BaseType (typeof (NSObject))] + interface NISession + { + [Static] + [Export ("supported")] + bool IsSupported { [Bind ("isSupported")] get; } + + [Wrap ("WeakDelegate")] + [NullAllowed] + INISessionDelegate Delegate { get; set; } + + [NullAllowed, Export ("delegate", ArgumentSemantic.Weak)] + NSObject WeakDelegate { get; set; } + + [NullAllowed, Export ("delegateQueue", ArgumentSemantic.Strong)] + DispatchQueue DelegateQueue { get; set; } + + [NullAllowed, Export ("discoveryToken", ArgumentSemantic.Copy)] + NIDiscoveryToken DiscoveryToken { get; } + + [NullAllowed, Export ("configuration", ArgumentSemantic.Copy)] + NIConfiguration Configuration { get; } + + [Export ("runWithConfiguration:")] + void Run (NIConfiguration configuration); + + [Export ("pause")] + void Pause (); + + [Export ("invalidate")] + void Invalidate (); + } + + interface INISessionDelegate {} + + [NoWatch, NoTV, NoMac, iOS (14,0)] + [Protocol] + [Model (AutoGeneratedName = true)] + [BaseType (typeof (NSObject))] + interface NISessionDelegate + { + [Export ("session:didUpdateNearbyObjects:")] + void DidSessionUpdateNearbyObjects (NISession session, NINearbyObject[] nearbyObjects); + + [Export ("session:didRemoveNearbyObjects:withReason:")] + void DidSessionRemoveNearbyObjects (NISession session, NINearbyObject[] nearbyObjects, NINearbyObjectRemovalReason reason); + + [Export ("sessionWasSuspended:")] + void SessionWasSuspended (NISession session); + + [Export ("sessionSuspensionEnded:")] + void SessionSuspensionEnded (NISession session); + + [Export ("session:didInvalidateWithError:")] + void DidSessionInvalidate (NISession session, NSError error); + } +} diff --git a/tests/introspection/ApiCtorInitTest.cs b/tests/introspection/ApiCtorInitTest.cs index 8014a9ca50..4088ae505b 100644 --- a/tests/introspection/ApiCtorInitTest.cs +++ b/tests/introspection/ApiCtorInitTest.cs @@ -68,6 +68,13 @@ namespace Introspection { return true; case "NEPacketTunnelProvider": return true; + // On iOS 14 (beta 4) we get: [NISimulator] To simulate Nearby Interaction distance and direction, launch two or more simulators and + // move the simulator windows around the screen. + // The same error occurs when trying to default init NISession in Xcode. + // It seems that it is only possible to create a NISession when there are two devices or sims running, which makes sense given the description of + // NISession from Apple API docs: "An object that identifies a unique connection between two peer devices" + case "NISession": + return true; case "NSUnitDispersion": // -init should never be called on NSUnit! case "NSUnitVolume": // -init should never be called on NSUnit! case "NSUnitDuration": // -init should never be called on NSUnit! diff --git a/tests/xtro-sharpie/iOS-NearbyInteraction.ignore b/tests/xtro-sharpie/iOS-NearbyInteraction.ignore new file mode 100644 index 0000000000..28d073d457 --- /dev/null +++ b/tests/xtro-sharpie/iOS-NearbyInteraction.ignore @@ -0,0 +1,3 @@ +## 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 diff --git a/tests/xtro-sharpie/iOS-NearbyInteraction.todo b/tests/xtro-sharpie/iOS-NearbyInteraction.todo deleted file mode 100644 index bba386146a..0000000000 --- a/tests/xtro-sharpie/iOS-NearbyInteraction.todo +++ /dev/null @@ -1,26 +0,0 @@ -!missing-enum! NIErrorCode not bound -!missing-enum! NINearbyObjectRemovalReason not bound -!missing-field! NIErrorDomain not bound -!missing-field! NINearbyObjectDirectionNotAvailable not bound -!missing-field! NINearbyObjectDistanceNotAvailable not bound -!missing-protocol! NISessionDelegate not bound -!missing-selector! +NISession::isSupported not bound -!missing-selector! NINearbyObject::direction not bound -!missing-selector! NINearbyObject::discoveryToken not bound -!missing-selector! NINearbyObject::distance not bound -!missing-selector! NINearbyPeerConfiguration::initWithPeerToken: not bound -!missing-selector! NINearbyPeerConfiguration::peerDiscoveryToken not bound -!missing-selector! NISession::configuration not bound -!missing-selector! NISession::delegate not bound -!missing-selector! NISession::delegateQueue not bound -!missing-selector! NISession::discoveryToken not bound -!missing-selector! NISession::invalidate not bound -!missing-selector! NISession::pause not bound -!missing-selector! NISession::runWithConfiguration: not bound -!missing-selector! NISession::setDelegate: not bound -!missing-selector! NISession::setDelegateQueue: not bound -!missing-type! NIConfiguration not bound -!missing-type! NIDiscoveryToken not bound -!missing-type! NINearbyObject not bound -!missing-type! NINearbyPeerConfiguration not bound -!missing-type! NISession not bound diff --git a/tests/xtro-sharpie/macOS-NearbyInteraction.todo b/tests/xtro-sharpie/macOS-NearbyInteraction.ignore similarity index 65% rename from tests/xtro-sharpie/macOS-NearbyInteraction.todo rename to tests/xtro-sharpie/macOS-NearbyInteraction.ignore index be8289de1f..39e3525be6 100644 --- a/tests/xtro-sharpie/macOS-NearbyInteraction.todo +++ b/tests/xtro-sharpie/macOS-NearbyInteraction.ignore @@ -1,2 +1,3 @@ +## not available on macOS as of Xcode12 beta 4 !missing-enum! NIErrorCode not bound !missing-enum! NINearbyObjectRemovalReason not bound diff --git a/tools/common/Frameworks.cs b/tools/common/Frameworks.cs index 1c68a2f0a2..52124c15ed 100644 --- a/tools/common/Frameworks.cs +++ b/tools/common/Frameworks.cs @@ -341,6 +341,7 @@ public class Frameworks : Dictionary { "AppClip", "AppClip", 14,0 }, { "MediaSetup", "MediaSetup", new Version (14, 0), NotAvailableInSimulator /* no headers in beta 3 */ }, { "MLCompute", "MLCompute", new Version (14,0), NotAvailableInSimulator }, + { "NearbyInteraction", "NearbyInteraction", 14,0 }, { "SensorKit", "SensorKit", 14,0 }, { "UniformTypeIdentifiers", "UniformTypeIdentifiers", 14,0 }, diff --git a/tools/mtouch/Makefile b/tools/mtouch/Makefile index 37fb65a347..d238b8b2c6 100644 --- a/tools/mtouch/Makefile +++ b/tools/mtouch/Makefile @@ -165,6 +165,7 @@ SIMLAUNCHER_FRAMEWORKS = \ -weak_framework AppClip \ -weak_framework SensorKit \ -weak_framework UniformTypeIdentifiers \ + -weak_framework NearbyInteraction \ # keep the above list of weak_framework # 1. grouped by iOS versions;