Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit eb3658c29030846d9ffbe9f44e97619597f04d7e 1 parent 5bbe973
Matt Aimonetti authored December 30, 2008 drnic committed December 30, 2008

Showing 1 changed file with 13 additions and 4 deletions. Show diff stats Hide diff stats

  1. 17  download/lib/application.rb
17  download/lib/application.rb
@@ -23,6 +23,14 @@ def initiate_request(url_string, delegator)
23 23
     @connection = NSURLConnection.connectionWithRequest(request, delegate: delegator)
24 24
   end
25 25
   
  26
+  def connectionDidFinishLoading(connection)
  27
+    @status.text  = "Data totally retrieved"
  28
+    page          = NSString.alloc.initWithData(@receivedData, encoding:NSUTF8StringEncoding)
  29
+    @receivedData = nil
  30
+    @data.text    = page
  31
+    NSLog("data fully received")
  32
+  end
  33
+  
26 34
   # Deal with the data response
27 35
   # 
28 36
   # Note: in Ruby, the method name is the method signature
@@ -34,10 +42,11 @@ def connection(connection, didReceiveResponse:response)
34 42
   end
35 43
   
36 44
   def connection(connection, didReceiveData:receivedData)
37  
-    @status.text  = "Data retrieved"
38  
-    page          = NSString.alloc.initWithData(receivedData, encoding:NSUTF8StringEncoding)
39  
-    NSLog(page)
40  
-    @data.text    = page
  45
+    @status.text  = "Data being retrieved"
  46
+    # Initiate an ivar to store the received data
  47
+    @receivedData ||= NSMutableData.new
  48
+    @receivedData.appendData(receivedData)
  49
+    NSLog("data chunck received")
41 50
   end
42 51
 end
43 52
 

0 notes on commit eb3658c

Please sign in to comment.
Something went wrong with that request. Please try again.