objective c - Slow download with Apple sample code + progress -


I have implemented the following methods from the Apple site available on this page:

// My .h file: @ Interface app deliite: NSBKX & lt; NSAPProduction deliaget, NSWdodelGate, NSUrl downloadadminagate & gt; {Bull Elbjbodon; @ Private NSWRSports * Download Response; Receive long bytes; } // on my .m file: @implementation AppDelegate @ synthesize downloadResponse = _downloadResponse; @ Synthesis bytes received = _bytes received; // .... left .. - (IBAction) Startup process: (ID) Sender {// Some code is here ... [auto start application download]; } // Start down with the available apple code here: https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLDownload.html - (zero) start application download / URL: * Sender * / {// Create Request NSURLRequest * theRequest = [NSURLRequest requestWithURL: [NSURL URLWithString: @ "http://freefr.dl.sourceforge.net/project/hpc/hpc/g95/gfortran-4.9-bin.tar gz "] Cash Policy: NSURLRequestUseProtocolCachePolicy timeoutInterval: 30.0]; // Create the request with the request and start loading the data. Download NSURL * Download - [[Download the NS URL download] initWithRequest: theRequest Representative: Self]; If download (download!) // The user has failed to download NSLog ("download not started"); } Other {nslog (@ "start download"); }} - (Zero) Download: (Download Ns URL *) Download Decision Special NotificationFilename: (NSString *) Filename {NSString * destinationFilename; destinationFilename = [[[_home directory stringingbappinning path comparison: @ "desktop"] stringbapping path comparison: @ "down"] stringbappinging paired company: filename]; [DownloadState: DestinationFilename PermissionOverwriting: Yes]; } - (Zero) Download: (Download Ns URL *) Downloaded FileWrite Error: (NSError *) Error: // Notify user NSLog ("Download Failed! Error -% @% @", [Error Localized description], [[Error user information] ObjectFrench: NSURLErrorFailingURLStringErrorKey]); } - (zero) downloadDidFinish: Download Ns URL (download * *) // // Set any reference to the downloaded object // Do anything with data that can keep your app NSLog (@ "% @", @ " downloadDidFinish "); } - (zero) Setdown response: (nsrlr rowspons *) adloadations {nslog (@ "edoadspress -% @", edutuations); DownloadRePons = Download Response; NSLog (@ "Download Response -% @", Download Response); } - (Zero) Download: (Download Ns URL *) Downloaded Response Response: (nsrlr rsp * *) Response {// Reset progress, it can be called multiple times // Bites reassax is defined by another frequency variable variable. Bytes Rexide = 0; // Store the response to use later [self setdownloadations: feedback]; } - (Zero) Download: (Download Ns URL * *) Downloaded ReceivedAfalf Lamp: (unsigned long) length {long expected expected length = [expected expectant lamp] [download]; Receive bytes = receive bytes + length; If (expected length! = NSURLResponseUnknownLength) {// if the expected content length is available, display percent full percent. Float percent full = (expected bytes (/ expected by float) * 100.0; NSLog (@ "full percent -% F", percent complete); } else {// If the expected content length is unknown, then just log progress in NSLog (@ "bytes receive -% lld", bytes reexade); }}

Everything seems to work, but the download is really slow, trying to link in the safari, everything is very fast I think the code which calculates progress That part of (I will need for progress indicator), what to do with the brain Does anyone know how to fix speed problems?

Since the countless attempts, simple lines added:

  NSString * userAgent = @ "user"; [theRequest addValue: userAgent forHTTPHeaderField: @ "user-agent"];   

They have actually increased the speed of downloading in surprising terms. Maybe more things should be added, but now it is really satisfying.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -