Book Image

iOS Development with Xamarin Cookbook

By : Dimitrios Tavlikos (USD)
Book Image

iOS Development with Xamarin Cookbook

By: Dimitrios Tavlikos (USD)

Overview of this book

Table of Contents (22 chapters)
iOS Development with Xamarin Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Updating data in the background


In this recipe, we will learn how to make use of iOS 7's background fetch feature. This feature automatically wakes up the app at system-managed intervals, giving it a specific amount of time to retrieve data and update the UI.

Getting ready

Create a new Single View Application in Xamarin Studio and name it BackgroundFetchApp. Add a label to the controller.

How to do it...

Perform the following steps:

  1. We need access to the label from outside of the scope of the BackgroundFetchAppViewController class, so create a public property for it as follows:

    public UILabel LabelStatus {
      get { return this.lblStatus; }
    }
  2. Open the Info.plist file and under the Source tab, add the UIBackgroundModes key (Required background modes) with the string value, fetch. The following screenshot shows you the editor after it has been set:

  3. In the FinishedLaunching method of the AppDelegate class, enter the following line:

    UIApplication.SharedApplication.SetMinimumBackgroundFetchInterval(UIApplication...