Wisej.NET Hybrid
HomeNewsSupportVideos
  • Start
    • Introduction
    • Getting Started
    • Going Native with Wisej.NET Hybrid
    • Features
    • API
      • General
        • DeviceInfoBase
        • Device
        • DeviceException
        • DeviceInfo
        • DeviceEvent
        • DeviceException
        • HybridResourcesAttribute
      • Shortcuts
        • DeviceAppActions
        • DeviceAppActionsInfo
        • DeviceAppInfo
        • AppAction
      • Navigation
        • DeviceAppLinks
        • DeviceBrowser
        • DeviceLauncher
        • DeviceNavigation
        • DeviceWindows
        • DeviceWindowsInfo
        • AppLinkEntry
        • BrowserLaunchMode
        • BrowserLaunchOptions
        • BrowserTitleMode
      • Authentication
        • DeviceAuthenticator
        • IWebAuthenticatorResponseDecoder
        • WebAuthenticatorOptions
        • WebAuthenticatorResult
      • UI
        • DeviceBackground
        • DeviceBorder
        • DeviceBottomBar
        • DeviceColors
        • DeviceMenuBar
        • DevicePopups
        • DeviceStatusBar
        • DeviceTabBar
        • DeviceTheme
        • DeviceToolbar
        • MenuItemClickedEventArgs
        • MenuItem
        • MenuItemType
        • AppTheme
        • StatusBarTextColor
        • TabBarItem
        • TabSelectedEventArgs
        • AppTheme
        • ToolbarItem
        • ToolbarItemClickedEventArgs
        • ToolbarItemType
      • Hardware
        • DeviceBatteryInfo
        • DeviceFlashlight
        • BatteryPowerSource
        • BatteryState
        • EnergySaverStatus
        • EnergySaverStatusChangedEventArgs
      • Sharing
        • DeviceClipboard
        • DeviceSharing
      • Communication
        • DeviceContacts
        • DeviceEmail
        • DeviceEmailInfo
        • DeviceSms
        • DeviceSmsInfo
        • Contact
        • EmailMessage
        • SmsMessage
      • Network
        • DeviceNetworkingInfo
        • ConnectionProfile
        • ConnectivityChangedEventArgs
        • NetworkAccess
      • Display
        • DeviceDisplay
        • DeviceScreen
        • DisplayInfo
        • DisplayInfo
        • DisplayInfoChangedEventArgs
        • DisplayOrientation
        • DisplayRotation
        • Orientation
      • Storage
        • DeviceFileSystem
        • DevicePreferences
        • DeviceResources
        • DeviceSecureStorage
        • FileSystemInfo
      • Location
        • DeviceGeolocation
        • DeviceMap
        • AltitudeReferenceSystem
        • DistanceUnits
        • GeolocationAccuracy
        • GeolocationRequest
        • Location
        • Placemark
        • MapLaunchOptions
        • NavigationMode
      • Vibration
        • DeviceHapticFeedback
        • DeviceHapticFeedbackInfo
        • DeviceVibration
      • License
        • DeviceLicenseInfo
      • System
        • DeviceLifecycle
        • DeviceSystemInfo
        • DeviceVersioningInfo
        • AppPackagingModel
        • DeviceIdiom
        • DevicePlatform
        • DeviceType
      • Notifications
        • DeviceLocalNotification
        • DeviceLocalNotificationInfo
      • Logs
        • DeviceLogs
      • Media
        • DeviceMedia
      • Permissions
        • DevicePermissions
        • PermissionStatus
        • PermissionType
      • Sensors
        • DeviceSensorInfo
        • DeviceSensors
        • AccelerometerChangedEventArgs
        • AccelerometerData
        • BarometerChangedEventArgs
        • BarometerData
        • CompassChangedEventArgs
        • CompassData
        • GyroscopeChangedEventArgs
        • GyroscopeData
        • MagnetometerChangedEventArgs
        • MagnetometerData
        • OrientationSensorChangedEventArgs
        • OrientationSensorData
        • SensorChangedEventArgs
        • SensorType
      • Shell
        • DeviceFlyout
        • DeviceTitleBar
        • FlyoutBehavior
        • FlyoutHeaderBehavior
        • FlyoutItem
        • FlyoutItemSelectedEventArgs
      • Speech
        • DeviceSpeech
        • Locale
        • SpeechOptions
      • Converters
        • UnitConverters
    • Architecture
    • Troubleshooting
  • Development
    • Basics
    • Email
    • Haptic Feedback
    • Invoke .NET MAUI Code
    • Invoke Platform Code
    • Launch External Apps
    • License Activation
    • Local Application
    • MacOS Desktop Development
    • Multiple Windows (Desktop)
    • Network Events
    • Notifications
    • Open the Map App
    • Remote Application
    • Shortcuts (App Actions)
    • SVG Images & Icon Packs
    • Unit Converters
    • Updating the App
    • Vibration
  • Android
    • Soft Keyboard
  • Images
    • App Icons
    • Splash Screen
  • Debugging
    • Debugging Overview
    • Dev Tunnels
    • Android
    • iOS
    • Windows
  • REST Web Services
    • Detect network connectivity
    • REST with HttpClient
    • Use platform-specific network features
  • Storage
    • Compare Storage Options
    • Store Data locally with SQLite
  • Extensions
    • Overview
    • Document Scanner
    • Remote Push Notifications
  • Advanced
    • Custom Handler
    • iOS Build Mechanics
    • Multi-Targeting (Hybrid Local)
  • Samples
    • Wisej.NET Features
    • Examples on GitHub
  • Deployment
    • Deployment Overview
    • Deployment Guide
  • Application Profiling
    • Android
    • iOS / macOS
    • Windows
Powered by GitBook
On this page
  • Samples
  • Configuration
  • Switching Offline & Online Applications
  1. Development

Local Application

Wisej.NET Hybrid applications can be configured to run offline without any need to connect to a remote web server.

PreviousLicense ActivationNextMacOS Desktop Development

Last updated 1 year ago

Samples

Configuration

When creating a new Hybrid Client application, an offline application can be specified with the UseWisejOffline() extension method.

Startup.cs
public static MauiApp Main()
{
	var builder = MauiApp.CreateBuilder();
	builder
		.UseMauiApp<App>()

		 // Uncomment and replace with Offline startup Type to use embedded web server.
		 .UseWisejOffline<OfflineStartup>()

		// Uncomment when registering AppBuilderExtenders as part of a separate class library.
		// .UseWisejExtenders()

		.UseWisejHybrid((config) =>
		{
			// Uncomment to provide an offline fallback timeout.
			// config.OfflineTimeout = 5000;

			// Provide the startup URL for the Hybrid WebView.
			config.StartupUrl = "http://localhost:5000";
		});

	return builder.Build();
}

In the example above the client application registers an offline app, OfflineStartup, which runs an embedded web server that serves the Wisej.NET application:

OfflineStartup.cs
public class OfflineStartup
{
	public static string Main(CancellationToken token, object[] args)
	{
		var url = "http://localhost:5000";
		var server = new WebServer(url);
		server.WithWisej();
		server.WithStaticFolder("/", Path.GetDirectoryName(typeof(OfflineStartup).Assembly.Location), true);

		new Thread(() => server.RunAsync(token).Wait()).Start();

		return url;
	}
}

The default OfflineStartup file can be found within the Wisej.NET Hybrid Offline Application project template in Visual Studio.

Switching Offline & Online Applications

It is possible to switch between the offline (disconnected) application and online (connected) application with one few line of code:

At any point in time, simply use Application.Navigate("url", "target") to switch between URLs.

For example, if an offline application was registered on port 5000, but you're currently connected to an "online" application, you can use the following line of code anywhere in your Wisej.NET application to switch to the offline version:

Application.Navigate("http://localhost:5000");

Offline Fallback

If you would like to switch to the offline version of an application when the network gets disconnected, configure the OfflineTimeout member inside of the client app's Startup.cs file:

public static MauiApp Main()
{
	var builder = MauiApp.CreateBuilder();
	builder
		.UseMauiApp<App>()

		// Uncomment and replace with Offline startup Type to use embedded web server.
		.UseWisejOffline<OfflineStartup>()

		.UseWisejHybrid((config) =>
		{
			// Uncomment to provide an offline fallback timeout.
			config.OfflineTimeout = 5000;

			// Provide the startup URL for the Hybrid WebView.
			config.StartupUrl = "http://localhost:5000";
		});

	return builder.Build();
}

The line config.OfflineTimeout = 5000; in the example above specifies that when the user is no longer connected to a network, the application should automatically switch from the "online" version to the "offline" version of the application.

Wisej.NET Hybrid Offline Application
https://github.com/iceteagroup/wisej-hybrid-examplesgithub.com
LogoGitHub - unosquare/embedio: A tiny, cross-platform, module based web server for .NETGitHub
EmbedIO Source Code