Answer the question
In order to leave comments, you need to log in
How to get zip archive from server in iOS?
How to get zip archive from server in iOS?
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager.requestSerializer setValue:@"gzip" forHTTPHeaderField:@"Content-Encoding"];
NSString *url = [NSString stringWithFormat:@" http://sberbank-digest.mainsoft-open.eu.cloudbees.... ", idArchive];
[manager GET:url parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSLog(@"Success: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", [error localizedDescription]);
}];
XCode gives error:
Error: Request failed: unacceptable content-type: application/zip
Answer the question
In order to leave comments, you need to log in
- (void)loadZip {
NSString *mainUrl = [self.server stringByAppendingString:@"/files/YOURZIP.zip"];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:mainUrl]];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *respons,
NSData *dat,
NSError *connectionError) {
if (!connectionError) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"YOURZIP.zip"];
NSError *error;
BOOL flag = [dat writeToFile:appFile options:NSDataWritingAtomic error:&error];
if (flag) {
NSLog(@"You cool");
} else {
NSLog(@"%@", error.localizedDescription);
[self loadZip];
}
} else {
NSLog(@"%@",[connectionError localizedDescription]);
}
}];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question