This code works flawlessly on the simulator, writes out the file.
On the iPhone however, it does not write the file out.
DLog(@"");
timeStart = [NSDate date];
NSURL *url = [NSURL URLWithString:SAT_URL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:FILE_NAME];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
DLog(@"updated words to: %@",path);
//DLog(@"response: %@",responseObject);
[self processWords];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// Deal with failure
}];
[operation start];
rawWords and lines are all null on the device:
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:FILE_NAME];
NSString *rawWords = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSArray *lines = [rawWords componentsSeparatedByString:@"\n"];
This uses the AFNetworking lib and I’ve tried fetching the file from different hosters.
What am I doing wrong?
You cannot write to a bundle (definitely not on a device, maybe it is possible in the Simulator). You can write to a few predefined directories though (Cache, Documents). Check out the following post on StackOverflow: NSSearchPathForDirectoriesInDomains explanation confused