I have .json file in my Xcode project that contains much information. I can't fetch it each time because it's really big. But I'd like to update that file once a week in my app. Is it possible?
2 Answers
Maybe you can make a local notification that is fired once a week, and then download the file. Or you can even send push notifications to tell the app to download.
To download a file (in this case and unzip it using SSZipArchiver and AFNetworking for the download):
NSString *url = [NSString stringWithFormat:@"someurl"];
NSString *directoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
NSString *filePath = [directoryPath stringByAppendingPathComponent:[NSString stringWithFormat:@"nameofthefile.zip"]];
zipPath = filePath;
NSLog(@"DIRECTORY WHERE THE FILES ARE SAVED-->%@",directoryPath);
AFURLConnectionOperation *operation1 = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation1.outputStream = [NSOutputStream outputStreamToFileAtPath:filePath append:NO];
[operation1 setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead)
{
NSLog(@"-----> %f", (float)totalBytesRead / totalBytesExpectedToRead);
self.hud.progress = (float)totalBytesRead / totalBytesExpectedToRead;
}];
[operation1 setCompletionBlock:^()
{
[SSZipArchive unzipFileAtPath:zipPath toDestination:directoryPath overwrite:YES password:nil error:nil delegate:self];
}];
[operation1 start];
Here is some information: How to create local notifications Stackoverflow

- 1
- 1

- 658
- 1
- 7
- 20
-
but how can i save it and replace existing in my Xcode project? – Ruslan Serebriakov Sep 09 '15 at 19:43
You cannot replace the file in your Xcode project. You can only read resources from the application bundle. If you want to write you need to first copy the file to the application documents directory and modify it there.
Now you can download even large files in the background and replace the file in the writable directory when you are done.
Further remarks:
Think about how you could devise the web service to just send incremental changes. That seems so much more reasonable. Also, rather than parsing the content of a huge JSON file into memory, you might be better off using Core Data.

- 79,884
- 17
- 117
- 140