network.download problem ANSCA HELP!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
local function networkListener( event )
                if ( event.isError ) then
                
                        local function onComplete( event )
                    if "clicked" == event.action then
                        local i = event.index
                                if 1 == i then
                                   native.setActivityIndicator( false )
                                   end
                                end
                                end
 
                                -- Show alert with five buttons
                                local alert = native.showAlert( "Error", "Network issue", 
                                                                { "OK" }, onComplete )                                                                  
                        print ( "Network error - download failed" )
                        
                else
                    print( "download xml" )
                        native.setActivityIndicator( false )
                end
                    print ( "RESPONSE: " .. event.response )
                end
                
                network.download( "http://www.universopositivo.com.br/iphone/noticias.xml", "GET", networkListener, "noticias.xml", system.TemporaryDirectory )
                native.setActivityIndicator( true )

I believe the page/content is being cached by the OS so when you request the same page, it uses the cached content. Corona doesn't cache the data but calls the system's webview API.

Also: is the device you're using to test on iOS 5? I read various places that iOS 5 changed the way they handle cached content (within the Cached and tmp directories), so that could also be related.

so, what I can do to solve this problem?

I need to every time that I open my app, the XML file need to be downloaded to update some informations

yes, is a iOS 5

I would suggest saving to system.DocumentsDirectory instead to see if that helps (I think the iOS5 changes apply mainly to the Cahced and tmp directories).

Also, what mechanism were you using before to determine whether or not to use the cached version of your file vs. re-downloading? Seems like previously, you were intending to re-download every time to see if the server-version had changed.

I change know to DocumentsDirectory I will check if helps in iOS 5

my code to manege with this download and remove from device is this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
chegaConexao = function()
                local function networkListener( event )
                if ( event.isError ) then
                        print( "erro de internet" )
                else
                    print( "download xml" )
                        native.setActivityIndicator( false )
                end
                    print ( "RESPONSE: " .. event.response )
                end
                
                
                
                local function testeConexao( event )
                        if ( event.isError ) then
                                local function onComplete( event )
                    if "clicked" == event.action then
                        local i = event.index
                                if 1 == i then
                                   native.setActivityIndicator( false )
                                   end
                                end
                                end
 
                                -- Show alert with five buttons
                                local alert = native.showAlert( "Error", "Network issue", 
                                                                { "OK" }, onComplete )                                                                  
                        print ( "Network error - download failed" )
                        semInternet = true
                        
                        else
                                network.download( "http://www.universopositivo.com.br/iphone/noticias.xml", "GET", networkListener, "noticias.xml", system.DocumentsDirectory )
                                semInternet = false
                        end
                end
 
                -- Access Google over SSL:
                network.request( "https://google.com", "GET", testeConexao )
                native.setActivityIndicator( true )
                
                _G.carregarXMLs = false
        end
        
        if _G.carregarXMLs == true then
                timer.performWithDelay( 500, chegaConexao, 1 )
        end     
        --
        --
 
 
-------------------------------------------------------
-------------------------------------------------------
-- Here I have put a update button and this is his function
        atualiza = function()
                local destDir2 = system.DocumentsDirectory  -- where the file is stored
                local results2, reason2 = os.remove( system.pathForFile( "noticias.xml", destDir2  ) )
 
                if results2 then
                        print( "file removed" )
                else
                        print( "file does not exist", reason2 )
                end
                
                
                local function networkListener2( event )
                if ( event.isError ) then
                
                        local function onComplete2( event )
                    if "clicked" == event.action then
                        local i = event.index
                                if 1 == i then
                                   native.setActivityIndicator( false )
                                   end
                                end
                                end
 
                                -- Show alert with five buttons
                                local alert = native.showAlert( "Error", "Network issue", 
                                                                { "OK" }, onComplete2 )                                                                 
                        print ( "Network error - download failed" )
                        
                else
                    print( "download xml" )
                        native.setActivityIndicator( false )
                end
                    print ( "RESPONSE: " .. event.response )
                end
                
                
                local function testeConexao( event )
                        if ( event.isError ) then
                                local function onComplete( event )
                    if "clicked" == event.action then
                        local i = event.index
                                if 1 == i then
                                   native.setActivityIndicator( false )
                                   end
                                end
                                end
 
                                -- Show alert with five buttons
                                local alert = native.showAlert( "Error", "Network issue", 
                                                                { "OK" }, onComplete )                                                                  
                        print ( "Network error - download failed" )
                        semInternet = true
                        
                        else
                                network.download( "http://www.universopositivo.com.br/iphone/noticias.xml", "GET", networkListener2, "noticias.xml", system.DocumentsDirectory )
                                semInternet = false
                        end
                end
 
                -- Access Google over SSL:
                network.request( "https://google.com", "GET", testeConexao )
                native.setActivityIndicator( true )
        end
 
 
 
-------------------------------------------------------
-------------------------------------------------------
-- and in the same .lua down there I have put a fill functions to manege the remove file function
 
 
function onSystemEvent( event ) 
                if  "applicationSuspend" == event.type or "applicationExit" == event.type then
                        local destDir = system.TemporaryDirectory  -- where the file is stored
                        local results, reason = os.remove( system.pathForFile( "noticias.xml", destDir  ) )
 
                        if results then
                           print( "file removed" )
                        else
                           print( "file does not exist", reason )
                        end
                
                end
        end     
 
        Runtime:addEventListener( "system", onSystemEvent )
        
        
        
        function onSystemEvent2( event ) 
                if  "applicationResume" == event.type then
                        local function networkListener3( event )
                        if ( event.isError ) then
                
                                local function onComplete( event )
                                   if "clicked" == event.action then
                                        local i = event.index
                                                if 1 == i then
                                                   native.setActivityIndicator( false )
                                                   end
                                                end
                                                end
 
                                        -- Show alert with five buttons
                                        local alert = native.showAlert( "Error", "Network issue", 
                                                                { "OK" }, onComplete )                                                                  
                                print ( "Network error - download failed" )
                        
                        else
                            print( "download xml" )
                                native.setActivityIndicator( false )
                                end
                            print ( "RESPONSE: " .. event.response )
                        end
                
                        network.download( "http://www.universopositivo.com.br/iphone/noticias.xml", "GET", networkListener3, "noticias.xml", system.DocumentsDirectory )
                        native.setActivityIndicator( true )
                end
        end     
 
        Runtime:addEventListener( "system", onSystemEvent2 )
views:1789 update:2011/10/22 9:46:13
corona forums © 2003-2011