New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

Start learning with our library of video tutorials taught by experts. Get started

iOS SDK and SQLite: Building Data-Driven Apps
Illustration by Don Barnett

Finding a feed link in a web page


From:

iOS SDK and SQLite: Building Data-Driven Apps

with Bill Weinman

Video: Finding a feed link in a web page

Now that we have the Add View constructed, our first task is to get the URL for the RSS feed. Many website support the RSS autodiscovery specification using a link tag to point to the URL for an RSS feed. Our Add View controller will have support for either the URL of an RSS feed or the URL of a web page that supports RSS feed autodiscovery. When the user enters the URL, it could be either a web page or a feed. So the first thing we need to do is use NSURL Connection to fetch the URL.
Expand all | Collapse all
  1. 8m 29s
    1. Welcome
      57s
    2. Exercise files
      2m 17s
    3. Course overview
      3m 4s
    4. Application overview
      2m 11s
  2. 14m 49s
    1. Prototyping in a testbed
      1m 27s
    2. Building the view controller
      3m 45s
    3. Coding the testbed
      7m 56s
    4. Using the testbed
      1m 41s
  3. 37m 49s
    1. Understanding SQLite in iOS
      1m 41s
    2. Creating an Objective-C interface for SQLite
      9m 57s
    3. Testing the BWDB interface in the sandbox
      7m 1s
    4. Designing a database schema
      8m 7s
    5. Supporting the application with a specific interface
      7m 7s
    6. Using C pointers with automatic reference counting (ARC)
      3m 56s
  4. 21m 18s
    1. Understanding the table view
      1m 33s
    2. Creating the view controller
      6m 39s
    3. Reading from the database
      13m 6s
  5. 33m 50s
    1. Understanding the parsing process
      1m 57s
    2. Creating the item view controller
      12m 25s
    3. Reading data from the internet
      5m 30s
    4. Parsing the feed with NSXMLParser
      8m 2s
    5. Updating the item view with the feed items
      5m 56s
  6. 40m 14s
    1. Understanding the modal view
      1m 47s
    2. Constructing the view controller
      15m 5s
    3. Finding a feed link in a web page
      8m 55s
    4. Parsing the feed with NSXMLParser
      5m 4s
    5. Delegating back to the parent view
      6m 11s
    6. Deleting feeds
      3m 12s
  7. 21m 5s
    1. Creating the web view class
      12m 33s
    2. Coding the web view
      5m 25s
    3. Viewing pages in Safari
      3m 7s
  8. 14m 3s
    1. Understanding the iOS preferences system
      1m 23s
    2. Creating the preferences plist in Xcode
      7m 20s
    3. Reading preferences in your application
      5m 20s
  9. 6m 15s
    1. Adding pull-to-refresh functionality
      2m 34s
    2. Implementing the pull-to-refresh gesture for iOS 6
      3m 41s
  10. 27m 1s
    1. Understanding split view
      1m 4s
    2. Coding the table views
      11m 24s
    3. Implementing the iPad detail view
      6m 35s
    4. Implementing the iPad modal view
      7m 58s
  11. 35s
    1. Goodbye
      35s

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
please wait ...
iOS SDK and SQLite: Building Data-Driven Apps
3h 45m Intermediate Jan 16, 2013

Viewers: in countries Watching now:

The iOS software development kit (SDK) includes the popular SQLite library, a lightweight yet powerful relational database engine that is easily embedded into an application. In this course, Bill Weinman teaches you how to build an RSS reader for iOS devices, integrating XML data and a streamlined interface. He explains how to use the SQLite database, display information in a table view, code view controllers, and create a preferences pane for your app. The resulting application is optimized for all iPhone and iPad displays.

Topics include:
  • Prototyping the app
  • Coding and working with a testbed
  • Creating an Objective-C interface for SQLite
  • Designing a database schema
  • Creating the view controllers
  • Reading and writing to the database
  • Parsing the RSS feed with NSXMLParser
  • Updating the item view with feed items
  • Implementing the pull to refresh gesture for iOS 6
  • Creating a universal application with multiple views
Subjects:
Developer Mobile Apps Databases
Software:
iOS
Author:
Bill Weinman

Finding a feed link in a web page

Now that we have the Add View constructed, our first task is to get the URL for the RSS feed. Many website support the RSS autodiscovery specification using a link tag to point to the URL for an RSS feed. Our Add View controller will have support for either the URL of an RSS feed or the URL of a web page that supports RSS feed autodiscovery. When the user enters the URL, it could be either a web page or a feed. So the first thing we need to do is use NSURL Connection to fetch the URL.

Then we inspect the MIME type to find out if it's a web page or an RSS feed. If we have a web page, we need to look in the header section of the web page to see if there's a link tag pointing to an RSS feed, and then go fetch that URL and treat it as the feed. For example, Ars Technica here, if I press Option+Command+U--this is Chrome so that will show the source for the web page-- you notice down here we have this link tag right there: relationship, alternate, type, application rss+xml, and then the URL of the RSS feed.

So, that's the RSS autodiscovery right there. On the other hand, Macworld's web page, if I press Option+Command+U to view the source, you notice there are a lot of link tags here, but those are all relationship style sheet. There is no RSS autodiscovering in this page. If I just search for the letters RSS on the page, all we find is this link to another page with the RSS feeds on it. So macworld.com is not supporting the RSS autodiscovery.

Our implementation here in BWRSS is a very simple implementation that works in most circumstances. It does not support multiple RSS feeds per page, nor does it support relative links. You can see the full specification for the RSS autodiscovery here at the RSS Advisory Board website. Now, let's set up our Add View Controller to discover and fetch an RSS feed. So, we're going to start with our addView-02, and I'm going to use the addView-02-done here. You can start with the code that you wrote in the last movie if you're following along.

I want to make a working copy of this, and I'm going to rename it to addView-03. I'm going to go ahead and open that in Xcode by double-clicking on the Xcode project file. I'm going to go ahead and hide this right-hand pane so we have a little more room on the screen here. I'm going to come back out to the Finder, and I'm going to open this methods.txt file, addView-03-methods.txt, in my text editor. And coming up here to the top of the file, I'm just going to grab the Error handling and Utilities, all the way down here to just before the RSS Feed Management.

I'm going to press Command+C on my keyboard and paste this into the bottom of this file, just above the @end there. There we have it. The error routines are very straight forward. And the utilities, we have the statusMessage. This is new. What it does is it takes a variadic formatted argument or argument list, and it formats it and sets these statusLabel. The best way to explain this is to show an example of it. If I come back up here to our button actions, and the addAction, I'm just going to comment out this dismissed view controller, and I'm going to say self statusMessage and Add button pressed.

And now, when I run this in the simulator-- select the iPhone Simulator and press Run-- and I'll bring up our Add Feed view-- And you notice when I press the Add button, you watch the statusMessage here on this text label. I press Add, and you see it says Add button pressed. Press Cancel, it goes way. If I do it again, you'll also notice, if I press this Done button down here, we get the same thing, Add button pressed. And that's because we have here textFieldShouldReturn.

This class is set up as the delegate for the textField and so anytime that button is pressed, it just calls addAction and then we get our statusMessage again. So that's what statusMessage does. It's variadic. It allows for parameters, and we'll see a lot more examples of it as we go through this code. Now, let's fetch the web object with NSURL connection. We're going to come back out here to where text file. We're just going to select everything else here, all the way down to the end.

You notice we have our button actions as well. Those are going to replace the ones. We'll move those ones we copied them in. So, let's go back into Xcode and come down here to the bottom, and I'm going to paste those in here. And you notice that these button actions, they get the error because they're duplicate. I'm just going to cut with Command+X and come back up here to our button actions and paste them in there. Press Command+S to save.

So what we have here now, you'll notice in Add action, we're calling getRSSFeed, and we find that down here in RSS Feed Management. getRSSFeed, it first fixes up the URL to make sure that it has either a prefix of HTTP or HTTPS. And if not, it adds that by appending the string. And then it calls fetchURL, and fetch URL actually sets up the URL request with NSURLRequest. Aetting the delegate to self, and it calls that and passes off all of our execution to the NSURL delegate methods.

Our NSURL delegate methods are very straightforward. You notice a lot of these methods are checking the BWRSSState to see if we're in the Parse Header or State Discovery mode. If we're in the State Discovery mode, then we're actually looking through an HTML file to find that RSS Discovery link tag, and if we're in the Parse Header mode then we're actually going through an XML file and reading the RSS data. But the rest of this we've mostly seen before. When we received before when we receive data, we append it into our mutable data structure. And on DidFinishLoading, depending on if we're on the discovery mode or the parse mode, we call the appropriate function.

Now at this point, we're not ready to start parsing things yet, so we're going to go ahead and comment this out and comment this out. And I want to put in a little status message here so that we can see that we are actually getting the data from the feed, so I'm going to say self statusMessage, and I'm going to say Have, %d bytes of data, and we're going to get that from our xmlData.length. So, we save that with Command+S.

Make sure the iPhone Simulator is selected, and I'm going to press the Run button. Looks like I didn't stop it last time. That's okay. I just press Stop, and I'm going to bring up our Add View Controller and type in cnn.com this time, because I know that's a good amount of data. I'm going to press the Add button, and here we have it, Have 134,791 bytes of data. Of course, your result will be somewhat different than that because I'm sure they change their website constantly.

So at this point, we have fetched the web object, and you can see that result there and in DidReceiveResponse, we can check the mime type to find out if it's a web page or an RSS feed. If it's a web page, we need to check for a link tag that will point us to the actual RSS feed, and this is done in the rssLinkFromHTML code. Stop our simulator. There's the rssLinkFromHTML. And you'll notice that it uses the NSScanner object to scan through and look for a link, the relationship, and the type, and if it has the correct mime type.

And so, if we come back up here to connectionDidFinishLoading--and we will uncomment this so that now we're calling findFeedURL--and then, down here in the StateParseHeader, we can put in a new statusMessage, and we'll go ahead and run this again in the Simulator. Type in cnn.com and press Add, and now we have an RSS feed. So, now we have found and retrieved the RSS feed from a web server.

This involved fetching the provided URL and determining if it was a web page or an RSS feed, and for the RSS feed we simply fetch the feed for parsing, and for web pages we search for the first link tag that links to an RSS feed and fetch that for parsing as a feed. Now we can go ahead and parse the feed using NSXMLParser, and we'll do that in the next movie.

Find answers to the most frequently asked questions about iOS SDK and SQLite: Building Data-Driven Apps.


Expand all | Collapse all
please wait ...
Q: Why is the RSSDB library in the exercise files different than the one in the videos?

A: The RSSDB library had to be updated to work around a bug in the iOS 7 SDK.

There is a bug in the iOS 7 SDK that prevents the BWDB fast enumeration implementation from working on a device. The symptom is code that runs fine on the emulator, but not on a device. iOS devices use an ARM processor, while the emulator runs on your Mac's Intel processor. This points to the LLVM ARM code generator as the source of the bug. Because the bug appears to be in the LLVM compiler, it may be some time before it is fixed.

As a workaround we have changed the getFeedIDs and getItemIDs methods in the RSSDB library so they don't use Objective C fast enumeration. 

Please note that this same bug also affects some of the BWDB testbed code in Chapter 2. The result is that it will run on the emulator but not on a device.

Q: After upgrading to Xcode 5.1 I get an error that says:

"Used type va_list (aka_builtin_va_list) where arithmetic or pointer type is required"

A: Please download the exercise files again to get the latest version of the BWDB library.
 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.
Upgrade now


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

join now Upgrade now

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed iOS SDK and SQLite: Building Data-Driven Apps.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.