-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DeviceDiscoveryUI] Added bindings for DeviceDiscoveryUI. (#20271)
Follow-up of #15762. --------- Co-authored-by: Israel Soto <[email protected]>
- Loading branch information
1 parent
e462d9e
commit 58e382e
Showing
14 changed files
with
236 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// Custom methods for DDDevicePickerViewController | ||
// | ||
// Authors: | ||
// Israel Soto <[email protected]> | ||
// | ||
// Copyright 2022 Microsoft Corporation. | ||
// | ||
|
||
#nullable enable | ||
|
||
using ObjCRuntime; | ||
using Foundation; | ||
using Network; | ||
using System; | ||
|
||
using OS_nw_endpoint = System.IntPtr; | ||
using OS_nw_error = System.IntPtr; | ||
|
||
namespace DeviceDiscoveryUI { | ||
|
||
public partial class DDDevicePickerViewController { | ||
/// <summary> | ||
/// The type of the delegate that will be called when the user selects a device in the list of devices. | ||
/// </summary> | ||
public delegate void DevicePickerCompletionHandler (NWEndpoint? endpoint, NWError? error); | ||
|
||
/// <summary> | ||
/// Checks if device discovery is supported for the current device | ||
/// </summary> | ||
public static bool IsSupported (NWBrowserDescriptor browseDescriptor, NWParameters? parameters) => | ||
_IsSupported (browseDescriptor.GetNonNullHandle (nameof (browseDescriptor)), parameters.GetHandle ()); | ||
|
||
/// <summary> | ||
/// A view controller that lists other devices on your network. | ||
/// </summary> | ||
/// <remarks> | ||
/// Verify if this controller is supported by calling DDDevicePickerViewController.IsSupported before creating an instance, as this will crash if not supported. | ||
/// </remarks> | ||
[DesignatedInitializer] | ||
public DDDevicePickerViewController (NWBrowserDescriptor browseDescriptor, NWParameters? parameters) : base (NSObjectFlag.Empty) => | ||
InitializeHandle ( | ||
_InitWithBrowseDescriptorAndParameters (browseDescriptor.GetNonNullHandle (nameof (browseDescriptor)), parameters.GetHandle ()), | ||
"initWithBrowseDescriptor:parameters:"); | ||
|
||
/// <summary> | ||
/// Set the delegate that will be called when the user selects a device in list of devices. | ||
/// </summary> | ||
public void SetDevicePicker (DevicePickerCompletionHandler devicePickerCompletionHandler) | ||
{ | ||
_SetDevicePicker (InternalDevicePickerCompletionHandler); | ||
|
||
void InternalDevicePickerCompletionHandler (OS_nw_endpoint endpoint, OS_nw_error error) | ||
{ | ||
NWEndpoint? ep = endpoint != IntPtr.Zero ? new NWEndpoint (endpoint, false) : null; | ||
NWError? er = error != IntPtr.Zero ? new NWError (error, false) : null; | ||
|
||
devicePickerCompletionHandler (ep, er); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// DeviceDiscoveryUI C# bindings | ||
// | ||
// Authors: | ||
// Israel Soto <[email protected]> | ||
// | ||
// Copyright 2022 Microsoft Corporation. | ||
// | ||
|
||
using System; | ||
using Foundation; | ||
using ObjCRuntime; | ||
using UIKit; | ||
|
||
using OS_nw_browse_descriptor = System.IntPtr; | ||
using OS_nw_parameters = System.IntPtr; | ||
using OS_nw_endpoint = System.IntPtr; | ||
using OS_nw_error = System.IntPtr; | ||
|
||
#if !NET | ||
using NativeHandle = System.IntPtr; | ||
#endif | ||
|
||
namespace DeviceDiscoveryUI { | ||
|
||
[Internal] | ||
delegate void _DevicePickerCompletionHandler ([NullAllowed] OS_nw_endpoint endpoint, [NullAllowed] OS_nw_error error); | ||
|
||
[NoMac, NoiOS, NoMacCatalyst, NoWatch, TV (16, 0)] | ||
[BaseType (typeof (UIViewController))] | ||
[DisableDefaultCtor] | ||
interface DDDevicePickerViewController { | ||
[Internal] | ||
[Static] | ||
[Export ("isSupportedForBrowseDescriptor:parameters:")] | ||
bool _IsSupported (OS_nw_browse_descriptor browseDescriptor, [NullAllowed] OS_nw_parameters parameters); | ||
|
||
[Internal] | ||
[Export ("initWithBrowseDescriptor:parameters:")] | ||
NativeHandle _InitWithBrowseDescriptorAndParameters (OS_nw_browse_descriptor browseDescriptor, [NullAllowed] OS_nw_parameters parameters); | ||
|
||
[Internal] | ||
[Export ("setDevicePickerCompletionHandler:")] | ||
void _SetDevicePicker (_DevicePickerCompletionHandler devicePickerCompletionHandler); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
tests/monotouch-test/DeviceDiscoveryUI/DDDevicePickerViewControllerTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// | ||
// Unit tests for DDDevicePickerViewController | ||
// | ||
// Authors: | ||
// Israel Soto <[email protected]> | ||
// | ||
// Copyright 2022 Microsoft Corporation. | ||
// | ||
|
||
#if __TVOS__ | ||
|
||
using System; | ||
using DeviceDiscoveryUI; | ||
using Foundation; | ||
using ObjCRuntime; | ||
using Network; | ||
using NUnit.Framework; | ||
using Xamarin.Utils; | ||
|
||
namespace MonoTouchFixtures.DeviceDiscoveryUI { | ||
|
||
[TestFixture] | ||
[Preserve (AllMembers = true)] | ||
public class DDDevicePickerViewControllerTest { | ||
|
||
const string serviceName = "MyAppService"; | ||
|
||
[OneTimeSetUp] | ||
public void Init () => TestRuntime.AssertXcodeVersion (14, 0); | ||
|
||
[Test] | ||
public void IsSupportedTest () | ||
{ | ||
var browserDescriptor = NWBrowserDescriptor.CreateApplicationServiceName (serviceName); | ||
var parameters = NWParameters.CreateApplicationService (); | ||
var isSupported = DDDevicePickerViewController.IsSupported (browserDescriptor, parameters); | ||
|
||
// DDDevicePickerViewController seems to work only for devices | ||
if (TestRuntime.IsSimulator) | ||
Assert.IsFalse (isSupported, "IsSupported"); | ||
else | ||
Assert.IsTrue (isSupported, "IsSupported"); | ||
} | ||
|
||
[Test] | ||
public void InitWithBrowseDescriptorAndParametersTest () | ||
{ | ||
// DDDevicePickerViewController seems to work only for devices | ||
TestRuntime.AssertNotSimulator (); | ||
|
||
var browserDescriptor = NWBrowserDescriptor.CreateApplicationServiceName (serviceName); | ||
var parameters = NWParameters.CreateApplicationService (); | ||
var isSupported = DDDevicePickerViewController.IsSupported (browserDescriptor, parameters); | ||
|
||
// If this fails, please, double check that MyAppService is registered within the Info.plist | ||
// https://developer.apple.com/documentation/bundleresources/information_property_list/nsapplicationservices | ||
Assert.IsTrue (isSupported, $"The {serviceName} key might not be registered in the Info.plist."); | ||
|
||
Assert.DoesNotThrow (() => { var devicePicker = new DDDevicePickerViewController (browserDescriptor, parameters); }, | ||
"InitWithBrowseDescriptorAndParameters"); | ||
} | ||
|
||
[Test] | ||
public void SetDevicePickerTest () | ||
{ | ||
// DDDevicePickerViewController seems to work only for devices | ||
TestRuntime.AssertNotSimulator (); | ||
|
||
var browserDescriptor = NWBrowserDescriptor.CreateApplicationServiceName (serviceName); | ||
var parameters = NWParameters.CreateApplicationService (); | ||
var isSupported = DDDevicePickerViewController.IsSupported (browserDescriptor, parameters); | ||
|
||
// If this fails, please, double check that MyAppService is registered within the Info.plist | ||
// https://developer.apple.com/documentation/bundleresources/information_property_list/nsapplicationservices | ||
Assert.IsTrue (isSupported, $"The {serviceName} key might not be registered in the Info.plist."); | ||
|
||
Assert.DoesNotThrow (() => { | ||
var devicePicker = new DDDevicePickerViewController (browserDescriptor, parameters); | ||
devicePicker.SetDevicePicker ((endpoint, error) => { }); | ||
}, | ||
"SetDevicePicker"); | ||
} | ||
} | ||
} | ||
|
||
#endif // __TVOS__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
tests/xtro-sharpie/api-annotations-dotnet/tvOS-DeviceDiscoveryUI.todo
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.