Skip to content

Manual Hosting

Manual hosting gives you full control when you can’t inherit from Shiny’s base classes — for example, when your app already has custom Application, AppDelegate, or Activity classes that you can’t change.

You call Host.Lifecycle methods directly from your existing platform code to hook Shiny into the native lifecycle.

  1. Install the NuGet package

    NuGet package Shiny.Core
  2. Build the host at app startup

    Create and run the Shiny host as early as possible in your app’s lifecycle.

    using Foundation;
    using UIKit;
    using Shiny.Hosting;
    namespace YourNamespace;
    public class AppDelegate : UIApplicationDelegate
    {
    public override bool FinishedLaunching(
    UIApplication application,
    NSDictionary launchOptions)
    {
    var host = HostBuilder.Create();
    // Register your Shiny modules and services here
    host.Build().Run();
    return base.FinishedLaunching(application, launchOptions);
    }
    }
  3. Wire up lifecycle callbacks

    Forward platform events to Host.Lifecycle from your existing classes.

    Add these to your AppDelegate:

    // Required for HTTP Transfers
    public override void HandleEventsForBackgroundUrl(
    UIApplication application,
    string sessionIdentifier,
    Action completionHandler)
    {
    Host.Lifecycle.OnHandleEventsForBackgroundUrl(
    sessionIdentifier, completionHandler);
    }
    // Required for Push Notifications
    public override void RegisteredForRemoteNotifications(
    UIApplication application, NSData deviceToken)
    {
    Host.Lifecycle.OnRegisteredForRemoteNotifications(deviceToken);
    }
    public override void FailedToRegisterForRemoteNotifications(
    UIApplication application, NSError error)
    {
    Host.Lifecycle.OnFailedToRegisterForRemoteNotifications(error);
    }
    public override void DidReceiveRemoteNotification(
    UIApplication application,
    NSDictionary userInfo,
    Action<UIBackgroundFetchResult> completionHandler)
    {
    Host.Lifecycle.OnDidReceiveRemoteNotification(
    userInfo, completionHandler);
    }
    // Required for deep links / universal links
    public override bool ContinueUserActivity(
    UIApplication application,
    NSUserActivity userActivity,
    UIApplicationRestorationHandler completionHandler)
    {
    Host.Lifecycle.OnContinueUserActivity(
    userActivity, completionHandler);
    return true;
    }
MethodPlatformUsed By
OnActivityOnCreateAndroidAll modules
OnNewIntentAndroidNotifications, Push
OnActivityResultAndroidVarious
OnRequestPermissionsResultAndroidAll modules
OnHandleEventsForBackgroundUrliOSHTTP Transfers
OnRegisteredForRemoteNotificationsiOSPush
OnFailedToRegisterForRemoteNotificationsiOSPush
OnDidReceiveRemoteNotificationiOSPush
OnContinueUserActivityiOSDeep links