Shiny.NET
Platform - UWP

UWP

  1. In order to process background tasks, you first need to create a "Windows Runtime Library"
  1. Add

|Area|Info| |---|---| |Description|| |Service|Shiny.Jobs.IJobManager |NuGet|| |Static Generated Class|ShinyJobs

using Microsoft.Extensions.DependencyInjection;
using Shiny;

namespace YourNamespace
{
    public class YourShinyStartup : ShinyStartup
    {
        public override void ConfigureServices(IServiceCollection services, IPlatform platform)
        { 
            
<p>services.RegisterJob 
        }
    }
}

Minimum Version: 8.0

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8" ?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.org.yourapp" android:installLocation="preferExternal">
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.BATTERY_STATS" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
</manifest>

Minimum Version: 10

AppDelegate

using System;
using Foundation;
using Xamarin.Forms.Platform.iOS;
using Shiny;

namespace YourIosApp { [Register("AppDelegate")] public partial class AppDelegate : FormsApplicationDelegate { public override bool FinishedLaunching(UIApplication app, NSDictionary options) { this.ShinyFinishedLaunching(new Samples.SampleStartup()); global::Xamarin.Forms.Forms.Init(); this.LoadApplication(new Samples.App()); } public override void PerformFetch(UIApplication application, Action<UIBackgroundFetchResult> completionHandler) => this.ShinyPerformFetch(completionHandler); } }

Info.plist

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE plist PUBLIC " -//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
&lt;key&gt;BGTaskSchedulerPermittedIdentifiers&lt;/key&gt;
&lt;array&gt;
    &lt;string&gt;com.shiny.job&lt;/string&gt;
    &lt;string&gt;com.shiny.jobpower&lt;/string&gt;
    &lt;string&gt;com.shiny.jobnet&lt;/string&gt;
    &lt;string&gt;com.shiny.jobpowernet&lt;/string&gt;
&lt;/array&gt;
&lt;key&gt;UIBackgroundModes&lt;/key&gt;
&lt;array&gt;
   &lt;string&gt;processing&lt;/string&gt;
   &lt;string&gt;fetch&lt;/string&gt;
&lt;/array&gt;

</dict> </plist>

No Special Configuration Required

nuget to this new library.
  1. Add a references to your shared/netstandard library

  2. Add a class and call the following hook to Shiny

using System;
using Windows.ApplicationModel.Background;
using Shiny;


namespace Samples.UWP
{
    public sealed class MyShinyBackgroundTask : IBackgroundTask
    {
        public void Run(IBackgroundTaskInstance taskInstance)
            => this.ShinyRunBackgroundTask(taskInstance, new YourSharedLibrary.YourStartup());
    }
}

  1. Now add this "Windows Runtime Library" as a reference to your head UWP project.

  2. Add the following to your App.xaml.cs constructor in your head UWP project (Note the generic reference to your new runtime component)

this.ShinyInit<YourShinyBackgroundTask>(new YourSharedLibrary.YourStartup());
  1. In your Package.appxmanifest, add the following under the Application node (NOTE: the permissions you use will depend on the libraries from Shiny that you use)
<Extensions>
    <Extension Category="windows.backgroundTasks" EntryPoint="FullNamespaceToYour.ShinyBackgroundTask">
        <BackgroundTasks>
            <Task Type="bluetooth"/>
            <Task Type="deviceConnectionChange"/>
            <Task Type="deviceServicing"/>
            <Task Type="deviceUse"/>
            <Task Type="general"/>
            <Task Type="location"/>
            <Task Type="systemEvent"/>
            <Task Type="pushNotification"/>
            <Task Type="timer"/>
        </BackgroundTasks>
    </Extension>
</Extensions>

On This Page

UWP

Edit This Page