iOS Background Completion Server sample (.NET)

Overview

This sample is the .NET server for the iOS Background Completion scenario. It exposes a single deliberately slow service method that lets the iOS client demonstrate finishing a long-running remote call while the app is sent to the background.

The sample contains the server application only — it is used together with the iOS Background Completion client (Xcode), which discovers it on the network via ZeroConf/Bonjour.

Architecture

The server hosts a single iOSBackgroundCompletionService over an IpHttpServerChannel on port 8099 with a BinMessage. It advertises itself through ZeroConfRegistration (domain local.) so the iOS client can find it without a hard-coded address.

Getting started

  • Compile and run the application.
  • Make sure a ZeroConf facility (Bonjour) is running so the server is discoverable.
  • Run the iOS Background Completion client against it: the client calls Sleep, sends the app to the background, and shows that the call still completes when it returns to the foreground.

Examine the code

The service has a single method. It simply blocks for the requested number of seconds and returns a confirmation string — long enough for the client to background the app while the call is still in flight:

public virtual string Sleep(int Duration)
{
    System.Threading.Thread.Sleep(Duration * 1000);
    return String.Format("Slept well for {0} seconds.\r\nSincerely - your server.", Duration);
}

All the interesting logic for this scenario lives on the client (iOS) side — the server's only job is to take a measurable amount of time to answer.

Concepts Covered

See Also