此代码在模拟器上完美运行,写出文件。
但是,在 iPhone 上,它不会将文件写出。
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 和 lines 在设备上都是空的:
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:FILE_NAME];
NSString *rawWords = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSArray *lines = [rawWords componentsSeparatedByString:@"\n"];
这使用 AFNetworking 库,我尝试从不同的主机获取文件。
我究竟做错了什么?