Which is the best way to download database initial

2019-04-02 02:17发布

I am developing an application that on the user's first login must download a lot of data from my server and store it in a local database in my iOS app.

In my server I am using MySQL. And I need to download 70MB... to my iOS app to use this data locally, having or not connection.

What's the best way to download this data? XML zipped? Export to a SQLite file, zip this file, and download?

Can you recommend any approach?

3条回答
▲ chillily
2楼-- · 2019-04-02 02:28

We use web services and SOAP for transferring data from server to device. You should look into SOAP and REST web services. You basically get back xml which you can parse and use to create appropriate objects.

Although this may be a little too much for what you're trying to do, it's worth looking into.

Also, data can be stored in an SQLite Database, which is supported on most mobile platforms.

查看更多
戒情不戒烟
3楼-- · 2019-04-02 02:44

Yes you can export it to SQLite, zip it and download using AFNetworking.

NSString *yourFileURL=@"http://yourFileURL.zip";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:yourFileURL]];
AFURLConnectionOperation *operation =   [[AFHTTPRequestOperation alloc] initWithRequest:request];

NSString *cacheDir = [NSSearchPathForDirectoriesInDomains
                          (NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath = [cacheDir stringByAppendingPathComponent:
                      @"youFile.zip"];

operation.outputStream = [NSOutputStream outputStreamToFileAtPath:filePath append:NO];

[operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
   //show here your downloading progress if needed
}];

[operation setCompletionBlock:^{
    NSLog(@"File successfully downloaded");
}];

[operation start];
查看更多
虎瘦雄心在
4楼-- · 2019-04-02 02:48

If the database on the server is dynamic; A good approach is to build an API for accessing the Database data on the server, you can build an API through PHP and have the app just read the responses of data as JSON or XML.

Another approach if the database is static and wont update frequently is to add the SQL database to the IOS app as an SQLite database and just run local sql queries on the app.

查看更多
登录 后发表回答