Permalink
Browse files

improved the example showing how to check that a file is fully downlo…

…aded before processing it

Signed-off-by: Dr Nic Williams <drnicwilliams@gmail.com>
  • Loading branch information...
1 parent 5bbe973 commit eb3658c29030846d9ffbe9f44e97619597f04d7e @mattetti mattetti committed with Dec 30, 2008
Showing with 13 additions and 4 deletions.
  1. +13 −4 download/lib/application.rb
@@ -23,6 +23,14 @@ def initiate_request(url_string, delegator)
@connection = NSURLConnection.connectionWithRequest(request, delegate: delegator)
end
+ def connectionDidFinishLoading(connection)
+ @status.text = "Data totally retrieved"
+ page = NSString.alloc.initWithData(@receivedData, encoding:NSUTF8StringEncoding)
+ @receivedData = nil
+ @data.text = page
+ NSLog("data fully received")
+ end
+
# Deal with the data response
#
# Note: in Ruby, the method name is the method signature
@@ -34,10 +42,11 @@ def connection(connection, didReceiveResponse:response)
end
def connection(connection, didReceiveData:receivedData)
- @status.text = "Data retrieved"
- page = NSString.alloc.initWithData(receivedData, encoding:NSUTF8StringEncoding)
- NSLog(page)
- @data.text = page
+ @status.text = "Data being retrieved"
+ # Initiate an ivar to store the received data
+ @receivedData ||= NSMutableData.new
+ @receivedData.appendData(receivedData)
+ NSLog("data chunck received")
end
end

0 comments on commit eb3658c

Please sign in to comment.