O'Reilly logo

iOS 8 Swift Programming Cookbook by Vandad Nahavandipoor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 11. Networking and Sharing

11.0. Introduction

When iOS apps are connected to the Internet, they become more lively. For example, imagine an app that brings high-quality wallpapers to its users. The user can pick from a big list of wallpapers and assign any of those images as his iOS background. Now consider an app that does the same thing but adds to its list of wallpapers every day, week, or month. The user comes back to the app, and voilà! Tons of new wallpapers are dynamically added to the app. That is the magic of web services and the Internet. This can easily be achieved with basic knowledge of networking, XML, JSON, and sharing options, along with some creativity on the app developer’s part.

In this chapter, we are going to explore various classes that connect our applications with the Internet and social media. Take the NSURLSession class for example. This class replaces NSURLConnection and allows us to create sophisticated upload and download tasks that use block objects and are very configurable. For instance, as you will see in this chapter, using the NSURLSession class, we will be able to download content from a URL even when our application is in the background.

We also have at our disposal the Social framework that allows us to share user-created or app-created content with various social media services, such as FaceBook and Twitter. We are going to explore this framework as well in this chapter.

11.1. Downloading Data Using NSURLSession

Problem

You want to be able ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required