Basics

Validating Client

To validate if the client application is connected using Wisej.NET Hybrid, you can use:

bool valid = Wisej.Hybrid.Device.Valid;

Reading Device Information

Information about the hybrid client device is available using the Device.Info member. The Info member contains a number of predefined modules such as system, app version, and battery state information. These modules can be accessed using the following approach in C# and Wisej.NET:

// determine the power source of the connected hybrid device.
BatteryPowerSource powerSource = Device.Info.Battery.PowerSource;

// determine if this is a "first launch" of the application since installation.
bool isFirstLaunchEver = Device.Info.Versioning.IsFirstLaunchEver;

// determine hybrid client cache directory.
string cacheDirectory = Device.Info.FileSystem.CacheDirectory;

Some modules that register information about the hybrid client device are registered dynamically like those that are provided in the Wisej.NET Hybrid Extensions. Those modules can be accessed using the Device.Use<T>() method included where T is an implementation of IClientInfoProvider.

// get the type of biometrics supported by the device.
AuthenticationType = Device.Info.Use<AuthenticationInfoProvider>().AuthenticationType;

This same approach can be used to access built-in modules:

// determine hybrid client app data directory.
string cacheDirectory = Device.Info.Use<FileSystemInfoProvider>().AppDataDirectory;

Properties

A number of properties used to configure the hybrid client device are exposed through built-in modules such as Device.Flyout and Device.Email.

// set the device flyout items.
Device.Flyout.Items = new FlyoutItem[] {
    new FlyoutItem("Home", "Home.png"),
    new FlyoutItem("Settings", "Settings.png")
};

// determine if email composing is supported on the client hybrid device.
bool isComposeSupported = Device.Email.IsComposeSupported;

The first time a property is read from the value will be retrieved modally from the client device. This operation will suspend the current thread until a value is retrieved.

Alternatively, properties can be registered through dynamic modules such as those provided in the Wisej.NET Hybrid Extensions. These can be read from and assigned using the Device.Use<T> method where T is the name of the module type.

// set the statusbar background color
Device.Use<Statusbar>().BackColor = Color.Blue;

Methods

Methods can be used to interact with the hybrid client device's hardware or user interface such as toggling a flashlight or writing a file to the client device.

// enabling the device's flashlight.
Device.Flashlight.TurnOn();

// disabling the device's flashlight.
Device.Flashlight.TurnOff();

// write text to a file in the client app data directory.
var path = Path.Combine(Device.FileSystem.AppDataDirectory, "MyFile.txt");
Device.FileSystem.WriteAllText(path, "Hello, World!");

// show a native MAUI view modally and retrieve the response.
var fullyQualifiedName = "MyAssembly.MyType, MyAssembly";
var result = Device.Navigation.ShowDialog(fullyQualifiedName, "arg1", 2, 3);

Alternatively, some Wisej.NET Hybrid Extensions may register modules with methods dynamically. These can be called using the Device.Get<T> method where T is the name of the module type.

// authenticate a user
bool authenticated = Device.Use<DeviceAuthentication>().Authenticate();

In the case of calling any method that returns a value with Wisej.NET Hybrid, the operation is modal. The modal operation suspends the current thread until the value is returned from the client device.

Events

Events from the hybrid client device are automatically wired from the client device to the Wisej.NET application. Events can be accessed from a member of a built-in module such as Device.Battery, Device.Flyout, or Device.TabBar:

// attaching to a battery state event.
Device.Info.Battery.BatteryInfoChanged += Device_BatteryInfoChanged;

// attaching to a flyout item selection event.
Device.Flyout.ItemSelected += Device_FlyoutItemSelected;

Alternatively, dynamically registered modules such as the Wisej.NET Hybrid Extensions can be accessed and attached using the Device.Use<T>() method where T is the name of the module type.

// attaching to a registration event for remote notification tokens.
Device.Use<DeviceRemoteNotifications>().RegisteredForRemoteNotifications += Device_RegisteredForRemoteNotifications;

All Device member events should be manually disconnected when the event is no longer in use.

Last updated