例如,我的 ftp 服务器上有 100 个 JSON 文件和相应的 100 个图像。
1.加载JSON没有错误(我希望)
NSString *recipesPath = @"ftp://.../recipes/";
NSString *recipeFileName = [NSString stringWithFormat:@"00001.json", recipeCode];
NSString *recipeFileFullPath = [recipesPath stringByAppendingString:recipeFileName];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:recipeFileFullPath]];
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSError *error = nil;
NSDictionary *recipeDictionary = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
2.但是图片无法加载
NSString *recipeImageName = @"recipeImages/00001-1.jpg";
NSString *recipeImageFullPath = [recipesPath stringByAppendingString:recipeImageName];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:recipeImageFullPath]];
if (request) {
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
if (responseData) {
UIImage *image = [UIImage imageWithData:responseData];
}
}
responseData几乎总是nil。
可能有其他方法吗?
所有这些代码都在我执行的MyMethod中NSOperationQueue
:
operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(MyMethod) object:nil];
[operationQueue addOperation:operation];
编辑:图像尺寸不大 - 从 50 到 100 kbyte
编辑:图像文件扩展名会影响下载过程吗?