# Uno Platform

Initialize AppPortal in Uno native heads before App or AppHost construction, register the existing client, and choose optional navigation.

Source: https://appportal.io/docs/sdks/dotnet/uno

Initialize AppPortal in each executable entry point before Uno constructs `App` or its host.
Android and Apple initialization is owned by the native SDK and does not depend on Uno.
The same rule applies to Skia Desktop on Linux, macOS and Windows Win32.
Windows Win32 is a host backend for Skia; it is not the native WinUI renderer.
See [host availability](#host-availability) for BrowserWasm and native WinUI limitations.

The SDK owns crash capture, storage and delivery within each host's capabilities. Automatic native
lifecycle observation covers Android, Apple, Windows, Linux/X11 and BrowserWasm; the remaining host limitations
are described below. Host/DI registration only exposes the already-current `IAppPortalClient`;
it does not initialize or replace it.

## 1. Install

For Uno Skia applications, install the public 3.0.384 release from NuGet.org:

```bash
dotnet add package AppPortal.Telemetry.Uno --version "3.0.384"
```

If AppPortal supplied a different release, use its package source and exact version.
See [version notes](https://appportal.io/docs/getting-started/documentation-versions) before updating an existing app.

For an older Uno project with `AppPortal.Telemetry.Uno.Skia`, replace that reference with the
single Uno package when upgrading to 3.0.384 and check the [supported hosts](#host-availability).

Shared libraries using `IAppPortalClient` reference `AppPortal.Telemetry` and use the application's
client without initializing another runtime.

## 2. Initialize before Uno starts




### Android

Update the existing native Application constructor:

```csharp
using Android.Runtime;
using AppPortal;

public AndroidApplication(IntPtr javaReference, JniHandleOwnership transfer)
    : base(() => new App(), AppPortalSdk.CreateBuilder("<app-credential>").Start(javaReference), transfer)
{
}
```

The native Application already exists. `Start(javaReference)` initializes telemetry from its
existing reference and returns that reference unchanged. Initialization completes before Uno's
managed base constructor runs. The SDK owns JNI reference handling and native lifecycle hooks.

Keep initialization in the native Application even when the app can launch only to do background
work. Such a launch may never create an Activity, a MAUI/Uno host, or a Prism container. That
background code can use the SDK directly; do not create a second runtime or wait for UI registration.

Cold-start timing begins at this native root before SDK runtime/storage recovery and ends at the
first Activity resume. It includes Uno application setup and any delay before MainActivity creation.
The application supplies no stopwatch, lifecycle forwarding, or startup-complete callback.




### iOS, Mac Catalyst and tvOS

Start in `Main` before UIKit creates the application and delegate:

```csharp
using AppPortal;
using UIKit;

private static void Main(string[] args)
{
    AppPortalSdk.CreateBuilder("<app-credential>").Start();
    UIApplication.Main(args, null, typeof(App));
}
```

Keep the existing third argument to `UIApplication.Main` in your iOS head; some heads use a
different application/delegate type. Only add `Start()` before that call.

If the existing head uses `UnoPlatformHostBuilder` for UIKit, place `Start()` before constructing
that builder and keep its existing host setup. Do not initialize in `App` or `OnLaunched`.




### Desktop (Skia)

Desktop initialization precedes the native host builder:

```csharp
using AppPortal;
using Uno.UI.Hosting;

[STAThread]
public static void Main(string[] args)
{
    AppPortalSdk.CreateBuilder("<app-credential>").Start();

    var host = UnoPlatformHostBuilder.Create()
        .App(() => new App())
        .UseX11()
        .UseLinuxFrameBuffer()
        .UseMacOS()
        .UseWin32()
        .Build();
    host.Run();
}
```

Keep only the backends your application already uses. This example starts the SDK before the
existing Uno host; `services.AddAppPortalUno()` later registers that same client.
Windows Win32, macOS, and Linux/X11 are desktop hosts for Skia. XWayland uses the X11 path.

**Current limitation — Linux framebuffer:** automatic foreground/background, active-time and
display-based startup tracking are unavailable on this backend. Root initialization, crash capture
and explicit Prism telemetry remain available. No application lifecycle forwarding is required to
use those capabilities.
Uno's application fallback only observes events a host actually emits; attaching an application
never reports foreground or successful startup by itself.
Check [host compatibility](https://appportal.io/docs/sdks/compatibility#host-and-toolchain-requirements) for platform requirements and runtime limitations.




The examples pass the app credential explicitly. If you instead add `appportal.credential` to
AndroidManifest metadata or `AppPortalCredential` to Info.plist, the parameterless builder can
discover it at the same native root. Apply consent policy, optional
features and endpoint overrides there.

On supported Android, Apple, Windows and Linux/X11 hosts, native lifecycle capture needs no application lifecycle
subscriptions or AppHost callbacks.
Optional Uno XAML exception observation can attach to the existing client with
`application.UseAppPortal()`; this cannot initialize telemetry. The native-head application-factory
helper can attach that additional observation automatically after construction.

## Host availability

The Uno package currently integrates Skia applications. The operating-system host and the renderer
are separate choices: Android still initializes in its native Application, Apple UIKit heads initialize
before UIKit, and desktop hosts initialize before the Uno host builder.

**Browser WebAssembly:** runtime hooks exist, but there is no supported browser credential bootstrap.
Do not embed an SDK key, server key, or internal-service credential in browser code, or copy a keyed
native startup snippet into a BrowserWasm head. Browser runtime support also has no native process
crash hooks and cannot retain queued telemetry across a page reload. These limitations mean the
native setup examples do not establish a supported browser onboarding flow.

**Native Windows App SDK / WinUI:** the current Uno integration no longer includes native-renderer
or WinAppSDK integration. For Uno on Windows, use the desktop Skia/Win32 host. Generic managed
runtime and Frame observation APIs do not establish a complete native WinUI host integration;
there is no native WinUI bootstrap example in this guide.

## 3. Register the existing client

Add this to the existing Uno host's service registrations:

```csharp
using Microsoft.Extensions.DependencyInjection;

services.AddAppPortalUno(); // services.AddAppPortal() is equivalent
```

For a Prism container that exposes the SDK interface directly:

```csharp
using AppPortal;

containerRegistry.RegisterInstance<IAppPortalClient>(AppPortalSdk.Current);
```

The Microsoft DI helpers register the current instance immediately and preserve an existing
application/test override. They do not discover credentials, create a runtime when resolved, or
take ownership of native shutdown. Without a host, no DI registration is required.

Inject `IAppPortalClient` into testable application services, or use Prism's existing logging
interfaces with the [AppPortal logging adapter](https://appportal.io/docs/sdks/dotnet/prism). Do not add a second
telemetry initialization to `App.xaml.cs` or AppHost construction.

The configuration-taking `AddAppPortalUno` and application `UseAppPortal` overloads have been
removed. Move their configuration to native startup. Missing native startup registers the safe
no-op client; there is no late initialization fallback.

Connect the [consent decision](https://appportal.io/docs/sdks/dotnet/telemetry#connect-your-consent-ui). A saved decision
survives launches; initial collection policy is configured at the native root.

## 4. Observe Frame navigation

Navigation is an additional integration. If a native `Frame` owns the path, attach once after
creating it and before its first navigation:

```csharp
_navigationTelemetry = rootFrame.ObserveAppPortalNavigation(
    "root", options => options.PrimarySurface("root"));
rootFrame.Navigate(typeof(MainPage));
```

Keep the returned observation for the Frame's lifetime and dispose it when replacing the Frame.
It records screen changes, navigation outcomes and `ScreenLoad` timing when both navigation
boundaries were observed. It never reads navigation parameters or waits for deferred data loading.

Use `SecondarySurface("details")` for a secondary pane. When Prism Regions own a path, select the
[Prism observer](https://appportal.io/docs/sdks/dotnet/prism) for that path instead of also observing its native Frame.

## 5. Verify automatic telemetry

With consent granted, run the app, navigate, then background and resume it. Open **Sessions** in
the Dashboard and inspect its **Session story**. Native startup supplies lifecycle and startup
timing; the chosen navigation adapter adds screens and navigation timing. Supported managed HTTP
requests are measured automatically.

The native observers require no custom lifecycle events, flush loops, or AppHost initialization callbacks.
Upload [matching symbols](https://appportal.io/docs/guides/distribution) for useful crash stacks. A process dying before
the SDK can acquire storage still cannot guarantee a persisted report.

Continue with [application context, logs and events](https://appportal.io/docs/sdks/dotnet/telemetry).
