Xamarin.Forms Projects
上QQ阅读APP看书,第一时间看更新

Adding a bootstrapper on iOS

The Bootstrapper for iOS is a simple wrapper for the common bootstrapper defined in the .NET Standard library, but with the addition of an Init method that will be called at startup:

  1. In the root of the iOS project, create a new class called Bootstrapper.cs.
  2. Add the following code to it:
public class Bootstrapper : DoToo.Bootstrapper 
{
public static void Init()
{
var instance = new Bootstrapper();
}
}

The Init method may look strange since we don't retain a reference to the instance we create. Keep in mind, however, that we do keep a reference to a Resolver instance inside the Resolver class, which is itself a singleton. 

The final step for iOS is to call this Init method in the right place:

  1. Open up AppDelegate.cs.
  2. Locate the FinishedLaunching method and add the code in bold:
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
Bootstrapper.Init();
LoadApplication(new App());

return base.FinishedLaunching(app, options);
}