Web サービスがあり、次のコード行を使用して cocoa から HTTP 呼び出しを行います。
NSData *imageData = [[NSData alloc] initWithContentsOfUrl:url options: NSDataReadingUncached error:&error];
この URL から画像を読み込むのに 10 秒かかることもあれば、30 秒かかることもあります。この URL を通常のブラウザから読み込んでみましたが、1 ~ 2 秒かかりました。私は遅延読み込みを行っていますが、問題は、この URL のコンテンツを通常のブラウザーと比較して読み込むのにかかる時間です。両方のテストは、同じネットワークから実行されました。
ダウンロード.m
NSError *error;
NSData *imageData = [[NSData alloc] initWithContentsOfURL:self.photoRecord.URL options:NSDataReadingUncached error:&error];
NSMutableArray *jsonArray = [NSJSONSerialization JSONObjectWithData:imageData options:NSJSONReadingAllowFragments error:&myError];
NSMutableDictionary *pictureInfo = [jsonArray objectAtIndex:0];
NSString *picture;
picture = [pictureInfo valueForKey:@"Picture"];
NSData *base64Data = [[NSData alloc]initWithBase64Encoding:picture];
if (base64Data) {
UIImage *downloadedImage = [UIImage imageWithData:base64Data];
self.photoRecord.image = downloadedImage;
}
[(NSObject *)self.delegate performSelectorOnMainThread:@selector(imageDownloaderDidFinish:) withObject:self waitUntilDone:NO];
次に、メイン スレッドの PictureController.m で:
-(void) loadScrollViewWithPage:(NSUInteger)page{
....
NSIndexPath *myIndexPath = [NSIndexPath indexPathForRow:page inSection:0];
[self startOperationsForPhotoRecord:aRecord atIndexPath:myIndexPath];
}
- (void)startOperationsForPhotoRecord:(PictureRecord *)record atIndexPath:(NSIndexPath *)indexPath {
Download *imageD = [[Download alloc] initWithPhotoRecord:record atIndexPath:indexPath delegate:self];
[self.pendingOperations.downloadsInProgress setObject:imageD forKey:indexPath];
[self.pendingOperations.downloadQueue addOperation:imageD];
}
次に、ダウンロードが完了したときにUIImageViewを更新するデリゲートメソッドがあり、正常に機能しています。
ロードされるコンテンツのサイズは約 400kb です。
何か案は?