34568

download and save zip file to iphone

Question:

i want to download the zip file from web but unable to figure out that how it is possible

i can download image /text/xml file but unable to download a zip file

Can someone guide me how to download zip files from web?

Thanks

Answer1:

If you're using <a href="http://developer.apple.com/library/ios/#documentation/cocoa/reference/foundation/Classes/NSURLConnection_Class/Reference/Reference.html" rel="nofollow">NSURLConnection</a>, it works exactly the same way no matter which type the file has.

<hr />

<strong>Example:</strong> (typed off of my head, no guarantee that it works this way and you should obviously implement error checking)

- (void) download { self.loadedData = [NSMutableData data]; // make 'loadedData' a property of the class NSURL *url = [NSURL URLWithString:@"http://..."]; NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:20.0]; [urlRequest setValue:@"Optional User Agent" forHTTPHeaderField:@"User-Agent"]; // shoot it off NSURLConnection *mainConnection = [NSURLConnection connectionWithRequest:urlRequest delegate:self]; if (nil == mainConnection) { NSLog(@"Could not create the NSURLConnection object"); } }

Then you must handle the incoming data in the delegate methods, e.g. to just save your data:

- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { [loadedData appendData:data]; }

Take a look at the <strong>other delegate methods</strong> and implement them, you should deal with authentification challenges and fail responses. You can also for example set:

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

in connection:didReceiveResponse: and set it to NO again in connectionDidFinishLoading:.

Recommend

  • Load part of matfile error: 'VARName' does not exist
  • How to add events to flash fallback for medialemetn and what evets are available?
  • Upload image to server ios
  • Extract frames from video in JS
  • How could connectionDidFinishLoading: run if no file is found on server? [duplicate]
  • Sending multipart request from iPhone to Ruby on Rails (RoR) server
  • What is the last function in iPhone application lifecycle
  • How can I do a 301 redirect from http to https in Wildfly 8.2?
  • Putting incomplete nested lists in a rectangular ndarray
  • shutdown and update job in Google Dataflow with PubSubIO + message guarantees
  • What I have to do to guarantee that ccc.jar is loaded before aaa.jar?
  • Javascript unload page condition
  • How to resolve dependencies from one gradle project to another gradle project in my Eclipse workspac
  • Specifying virtual keyboard type for EditText in XML
  • abstracting over a collection
  • How to explicitly/implicitly implemented interface members in C++/CLI?
  • How to programatically 'login' a user based on 'remember me' cookie when using j
  • Tell Git to stop prompting me for conflicts when none really exist?
  • android google indoor map
  • Insert new calendar with SyncAdapter- Calendar API Android
  • Django simple Captcha “No module named fields” error
  • Jquery UI tool tip close icon
  • Exchange data b/w iOS devices using Bluetooth 4.0
  • Display issues when we change from one jquery mobile page to another in firefox
  • C# - Serializing and deserializing static member
  • Bug in WPF DataGrid
  • Incrementing object id automatically JS constructor (static method and variable)
  • Hits per day in Google Big Query
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • embed rChart in Markdown
  • Linking SubReports Without LinkChild/LinkMaster
  • EntityFramework adding new object to nested object collection
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • Checking variable from a different class in C#
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • How to Embed XSL into XML
  • How can I use `wmic` in a Windows PE script?
  • failed to connect to specific WiFi in android programmatically
  • Unable to use reactive element in my shiny app
  • How can I use threading to 'tick' a timer to be accessed by other threads?