Updating sqlite database without XML

前端 未结 4 931
梦如初夏
梦如初夏 2020-12-11 05:00

My app requires data from a sqlite database. It will ship with a version of this database, but I need to update it on a regular basis (most likely once a month). Typically

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-11 05:39

    I ultimately ended up using AFNetworking to solve my problem, as suggested by @silver_belt. I was able to do it without subclassing AFHTTPClient though (see my answer here, which I posted as a follow up to this question).

    In the end, I just had to #include "AFHTTPRequestOperation.h" in my view controller's .h file, then in the .m I used

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"ftp://myUsername:myPassword@www.mysite.net/myfile.sqlite"]];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    NSURL *path = [[[app applicationDocumentsDirectory] URLByAppendingPathComponent:@"myfile"] URLByAppendingPathExtension:@"sqlite"];
    operation.outputStream = [NSOutputStream outputStreamWithURL:path append:NO];
    
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
        {
            NSLog(@"Successfully downloaded file to path: %@",path);
        }
                                     failure:^(AFHTTPRequestOperation *operation, NSError *error)
        {
            NSLog(@"Error in AFHTTPRequestOperation in clickedButtonAtIndex on FlightInfoController.m");
            NSLog(@"%@",error.description);
        }];
    
    [operation start];
    

    when I actually wanted to start my download. Hope this will make it easier for anyone looking to do this in the future!

提交回复
热议问题