RSS feed help

Hi.
So I’m at crunch time and I can’t get to get this thing working. Any help would be appreciated. I have similar code that works for iOS and it works fine on the simulator, but It won’t work when I build for device.

I think the problem is that it’s not saving what is downloaded to a file like it is suppose to. Anyone know why it wouldn’t do that on the device?

Here’s my code. Basically what’s happening is I’m downloading text from an RSS feed and spitting it out into a tableView.

Thanks in advance for any help. Sorry for any extra code that doesn’t belong to this issue.

[code]

module(…, package.seeall)

local widget = require(“widget”)
widget.setTheme( “theme_ios” )
local http = require(“socket.http”)
local ltn12 = require(“ltn12”)
local rss = require( “rss” )
local webpage = require(“webpage-PacRimStories”) – display story as a web popup
local ui = require(“ui”)
local utility = require(“utility”)
local print_r = utility.print_r

local feedName = “PacRimNewsNeeds.rss”
–local feedURL = “http://www.awanainternational.org/RSS/Adopt_a_Club.xml
local feedURL = “http://www.awanainternational.org/RSS/PacRim_Updates.xml
local displayMode = “webpage-PacRimStories”
local pageTitle = “Adopt! Tab 1”
local myList = nil
local stories = {}
local listGroup = display.newGroup()
local imageList = {}
local rowHeight =270
local function showTableView()
print(“Calling showTableView()”)
– native.showAlert(“table view called”, “table view called”, {“OK”})
–native.setActivityIndicator( true )
myList = widget.newTableView{ top = 37, width = display.contentWidth, height = 250, bgColor = {255,255,255,0} }

listGroup:insert(myList.view)

local function popUpClosed(event)
print(“popUpClosed”)
return true
end

local onItemRelease = function( event )
if event.phase == “release” then
–print_r(event.target)
–native.setActivityIndicator( true )
id = event.index
print(id)
local story = {}
story = stories[id]
print_r(story)
_G.story = story
director:openPopUp(“webpage-PacRimStories”, popUpClosed)
–local myPage = webpage.new()
– myPage = webpage.new(story, pageTitle)
end
return true
end

local function onRowRender(event)
print(“row render”)
–print_r(event)
local itemInfo = {
paddingTop = 20,
paddingLeft = 1,
paddingRight = 1,
thumbWidth = 60
}

local row = event.target
local rowGroup = event.view

local id = event.index
local tnailFilename = stories[id].imageFilename

if event.index > #stories then return true end
print(id)
print(stories[id].title)
– This gets called once a photo is done downloading, so now insert the image into the table row.
–[[ row.icon = display.newImage( tnailFilename, system.CachesDirectory)
local h = row.icon.contentHeight
local yScale = 200 / h
row.icon.xScale = yScale
row.icon.yScale = yScale
row.icon.alpha = 0
row.icon:setReferencePoint(display.TopLeftReferencePoint)
row.icon.x = 5
row.icon.y = 5
rowGroup:insert(row.icon)
transition.to( row.icon, { alpha = 1.0 } )
]]
local myTitle = string.sub(stories[id].title, 1, 36)
row.title = display.newText( myTitle, 12, 0, ArialBlack, 22 )
row.title:setReferencePoint( display.CenterLeftReferencePoint )
row.title.y = itemInfo.paddingTop
–row.title.x = itemInfo.paddingLeft + itemInfo.paddingRight + itemInfo.thumbWidth
row.title.x = screenLeft+30
row.title:setTextColor( 196,81,32,255 )

local format = {}
format.font = ArialMT
format.size = 15
format.lineHeight = 1.3
format.align = “left”
format.textColor = { 225, 225, 225 }
local timeStamp = string.sub(stories[id].description, 1)
row.subtitle = display.newParagraph( timeStamp, 50, format)
row.subtitle:setReferencePoint(display.CenterLeftReferencePoint )
row.subtitle.y = centerY-30
row.subtitle.x = screenLeft+100
–row.subtitle:setTextColor(255, 255, 255, 255)

local format = {}
format.font = ArialMT
format.size = 13
format.lineHeight = 1.3
format.align = “left”
format.textColor = { 144, 144, 144 }
local Date = string.sub(stories[id].link, 1)
row.subtitle2 = display.newParagraph( Date, 50, format)
row.subtitle2:setReferencePoint(display.CenterLeftReferencePoint )
row.subtitle2.y = itemInfo.paddingTop+20
row.subtitle2.x = screenLeft+60
–row.subtitle:setTextColor(255, 255, 255, 255)

row.rightArrow = display.newImageRect(“images/rightarrow.png”, 10, 14)
row.rightArrow.alpha = 0
row.rightArrow:setReferencePoint(display.TopLeftReferencePoint)
row.rightArrow.x = display.contentWidth - itemInfo.paddingRight - 10
row.rightArrow.y = itemInfo.paddingTop
– must insert everything into event.view:
rowGroup:insert(row.title)
rowGroup:insert(row.subtitle)
rowGroup:insert(row.subtitle2)
rowGroup:insert(row.rightArrow)
return true
end

for i = 1, #stories do

– fetch the pics from the server
local pic = {}
–if stories[id].thumbnail then
– pic = stories[id].thumbnail.url
–else
local id = i
if stories[id].enclosures then
pic = stories[id].enclosures[1]
local ext = “.jpg”
if pic.type == “image/jpeg” or pic.type == “image/png” then
if pic.type == “image/png” then
ext = “.png”
end
local basename = “pic” … id … “-” … string.format("%06d", math.random(1000000) - 1)
stories[id].imageFilename = basename … ext
stories[id].imageUrl = pic.url
stories[id].imageType = pic.type

tnailFilename = basename … “_t” … ext
local tnailUrl = pic.url
if stories[id].thumbnail.url then
tnailUrl = stories[id].thumbnail.url
end
print("thumbnail: " … tnailUrl)
– Create local file for saving data
local path = system.pathForFile(stories[id].imageFilename, system.CachesDirectory )
local myFile = io.open( path, “w+b” )

– Request remote file and save data to local file
http.request{
url = tnailUrl,
sink = ltn12.sink.file(myFile),
}
–myFile:close()
–network.download( tnailUrl, “GET”, imageLoaded, tnailFilename, system.TemporaryDirectory)
end
end

print(“insert row: " … i … " [” … stories[i].title … “]”)
myList:insertRow{
–onEvent = onItemRelease,
onRender = onRowRender,
height=rowHeight,
id = i,
isCategory = false,
rowColor = {255, 255, 255, 0},
lineColor = { 144, 144, 144, 1 },
}
end
native.setActivityIndicator( false )
end

function displayFeed(feedName, feedURL)

print(“entering displayFeed function 283”)

local function processRSSFeed(file, path)
print(“Parsing the feed processRSSFeed()”)
native.showAlert(“processRSSFeed”, (“this is before story is set”), {“OK”})
local story = {}
stories = rss.feed(file, path)
if stories == nil then
–native.showAlert(“line 292 stories = nil”, “stories = nil”, {“OK”})
print(“stories ==nil then show alert”)
local alert = native.showAlert( “We’re Sorry.”, “Looks like there is a problem connecting to the internet. Please make sure you are connected to the internet.”,
{ “OK” }, onAlertComplete )
else
–native.showAlert(“processRSSFeed”, “after rss.feed”, {“OK”})
–print_r(stories)
print(“processRSSFeed() from else 297”)
–native.showAlert(“Line 297 getting number of Stories”, “Number of stories”, {“OK”})
print("Num stories: " … #stories)
print("Got “, #stories, " stories, now show the tableView”)
showTableView()
end
end

local function onAlertComplete( event )
native.setActivityIndicator( false )
director:changeScene(“Region_PacRim”)
return true
end

local networkListener = function( event )
–utility.print_r(event)
–if ( event.isError ) then
–print(“Using Cached Copy network listner”)
–processRSSFeed(feedName, system.DocumentsDirectory)
– else
print(“calling processRSSFeed because the feed is avaialble”)
processRSSFeed(feedName, system.DocumentsDirectory)
–native.showAlert(“NetworkListener Called”, “not supported”, {“OK”})
–end
return true
end

local goToAndroid = 1
print(“Determine platform first”)
local platform = system.getInfo(“platformName”)
– if platform == “Android” then
if goToAndroid == 1 then
print(“Using Android now”)
– Android doesn’t support network detection at this point, so skip it.
–native.setActivityIndicator( true )
network.download(feedURL, “GET”, networkListener, feedName, system.DocumentsDirectory)
–[[ else
if network.canDetectNetworkStatusChanges then
print(“Using IOS now can detectNetwork Status”)
network.setStatusListener( “www.awanainternational.org”, MyNetworkReachabilityListener ) ]]
else
print(“Using Android now but Network no Go”)
native.showAlert(“network”, “not supported”, {“OK”})
print(“network reachability not supported on this platform”)
–end
end
end

– Called immediately after scene has moved onscreen:
new = function( params )
local localGroup = display.newGroup()

print(“Entering feed from 384”)
if _G.feedUrl then feedUrl = _G.feedUrl end
if _G.feedName then feedName = _G.feedName end

print(“calling displayFeed 435”)
displayFeed(feedName, feedURL)
function localGroup:clean()
print(“cleaning”)
if myList then
print(“removing list”)
myList:removeSelf()
end
myList = nil
end

return localGroup
end

[import]uid: 90878 topic_id: 21149 reply_id: 321149[/import]

Looks like i’m getting a pid error where the file is not being processed correctly .

Here’s the error as seen on logcat

< text >

01-31 08:42:18.739 1318 1477 I ActivityManager: Start proc com.awana for activity com.awana/com.ansca.corona.CoronaActivity: pid=32300 uid=10112 gids={3003}
01-31 08:42:18.747 32300 32300 E dalvikvm: could not disable core file generation for pid 32300: Operation not permitted

text >

Does anyone know why this is happening or how to fix it? [import]uid: 90878 topic_id: 21149 reply_id: 83790[/import]

Hey there,

I can’t go through that much code, although we do have the option of Premium Support for that.

That said, these two links may help you;
http://monkeybin.no/blog/archives/2011/04/26/creating-an-rss-and-json-driven-app-with-corona-sdk/
and;
https://github.com/robmiracle/Corona-SDK-RSS-Reader

The second is by our own RobMiracle :slight_smile:

Peach [import]uid: 52491 topic_id: 21149 reply_id: 83918[/import]