Time for action – fetching RSS
To fetch RSS perform the following steps:
Create a new blank mobile app by clicking on File | New | Titanium Project. Don't use a template, as it will just generate code that gets in the way.
This application will be a single window app, so remove all of the code from
app.js
replacing it with the following:var win1 = Titanium.UI.createWindow({ backgroundColor:'#fff' }); // open window win1.open();
Create a new file by clicking on File | New | File. Name the file
rssReader.js
. This file will be the CommonJS format RSS reader.Create a new public function
fetchRSSFeed
, which will return the RSS of a given URL. Write the following code that defines the function and sets up the HTTP request:exports.fetchRSSFeed = function(_args) { var xhr = Titanium.Network.createHTTPClient(); xhr.open('GET', _args.url);
Add an event to handle what should happen if a request should fail. In this case a function will be called.
xhr.onerror = function(e) { if...