With Corona SDK, is it possible to cache a blog that’s being taken from a RSS feed so it’s available offline? If so, where would I start?
Have you tried these? Some of them might be dated, but I don’t think the RSS specification has changed much in the past couple years.
https://github.com/robmiracle/Corona-SDK-RSS-Reader
http://coronalabs.com/blog/2013/10/09/a-look-inside-a-sample-corona-powered-business-app/
http://omnigeekmedia.com/templates/rss-reader-template-for-corona-sdk/
@BeyondtheTech is right. RSS hasn’t changed much and I can’t really add to his links as they are what I would point you to.
The only thing I will add, is that you use network.request() to fetch the RSS feed and save it in the system.CachesDirectory directory. It should stay there until you fetch a new one or the device gets low on space. In fact a good netizen would use a network.requesti() with a “HEAD” request to get the date of the feed to see if it’s newer than what you have and only request the feed if it’s newer.
Rob
Rob, is your template at http://omnigeekmedia.com/templates/rss-reader-template-for-corona-sdk/ running on Graphics 2.0? That seems like the best solution for me.
I don’t think I did make it Graphics 2.0. You’re better off with the Business sample app since it’s G2.0 and has been cleaned up more than that template.
Rob
Have you tried these? Some of them might be dated, but I don’t think the RSS specification has changed much in the past couple years.
https://github.com/robmiracle/Corona-SDK-RSS-Reader
http://coronalabs.com/blog/2013/10/09/a-look-inside-a-sample-corona-powered-business-app/
http://omnigeekmedia.com/templates/rss-reader-template-for-corona-sdk/
@BeyondtheTech is right. RSS hasn’t changed much and I can’t really add to his links as they are what I would point you to.
The only thing I will add, is that you use network.request() to fetch the RSS feed and save it in the system.CachesDirectory directory. It should stay there until you fetch a new one or the device gets low on space. In fact a good netizen would use a network.requesti() with a “HEAD” request to get the date of the feed to see if it’s newer than what you have and only request the feed if it’s newer.
Rob
Rob, is your template at http://omnigeekmedia.com/templates/rss-reader-template-for-corona-sdk/ running on Graphics 2.0? That seems like the best solution for me.
I don’t think I did make it Graphics 2.0. You’re better off with the Business sample app since it’s G2.0 and has been cleaned up more than that template.
Rob
Where can I find the Business Sample?
I migrated this into my app (thanks!) and I was able to read certain feeds:
But, when I tried some other feeds, it doesn’t seem to see the stories. I’m not an expert on RSS by any stretch, so I’m not sure what the difference is. Here are the one it won’t read:
http://www.ems1.com/ems-rss-feeds/news.xml
Other than the extension, I don’t know what the difference is.
I plugged in and it worked. You have to make sure you’re using the RSS parser and not the Atom parser. The feed.lua file in the Business Sample App defaults to an Atom feed.
Rob
EDIT: Sorry grabbed the wrong feed. let me look a bit more.
Rob
Okay, the reason the 2nd one doesn’t work is because the feed is invalid… See:
http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fwww.ems1.com%2Fems-rss-feeds%2Fnews.xml
What’s actually breaking things is that <language> tag at the top. The RSS parser expects the <channel> tag to be the first thing there… I’ve got a fix to get around this issue.
You will need to edit rss.lua and change this block of code:
if myFeed == nil then return nil end local items = myFeed.child[1].child local i print("Number of items: " .. #items)
to
if myFeed == nil then return nil end local items for i = 1, #myFeed.child do if myFeed.child[i].name == "channel" then items = myFeed.child[i].child break; end end print("Number of items: " .. #items)
It now searched through the whole feed to look for the channel tag instead of assuming that <channel> would be the first tag in the file. Of course, this helps harden the code which is a good thing, but still at the end of the day, the feed is invalid. That service should consider making sure their feeds pass validation.
Now there are other things that fail validation. I don’t know what impact that will have on parsing things further into the feed.
I may have found another bug in the XML parser and I need to do more testing before I can produce a patch for it. This will get you going for now.
Rob
Thanks! I can contact them about their feed… but who knows whether it will change.
Let me know if you patch the bug.
The bug in xml.lua seems to be that if an entry doesn’t end with a newline character, it looses the last character for string inside of CDATA tags. I just have to do more testing on more feeds to make sure the fix isn’t breaking something else. I’ve never noticed this before because most of the time there is a newline marker at the end.
I was able to get the new feed read in… BUT… only in the simulator. No matter what I try… when I build for Android… making sure I can get to the site… and the rss feed itself through chrome… I get a feed not available message and then it hangs.
Are you getting errors in your console log?
No errors… that I see… just the normal output about number of stories, and the output for each row. That’s the simulator, where it works. Obviously, there’s no console on the app - where it ISN’T working.
I’ve confirmed that I can get to the website on my phone, so I’m not sure what’s going on.
I did notice that the link:
http://www.ems1.com/ems-rss-feeds/news.xml
actually gives me a redirect message about downloading their app - but I assume that’s because of the browser version it detects when I try to view it. Could that have anything to do with it?