これは、@matttのアドバイスに従って、同様の問題で私がしたことです。私の Singleton InApp ヘルパーにはivarproductDownloadURL
と、呼び出し元prepareForDownload
に an を返すメソッドがあります。AFHTTPRequestOperation
- (AFHTTPRequestOperation * )prepareForDownload:(NSString *)productIdentifier
{
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:_productDownloadURL]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:productIdentifier];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];
return operation;
}
私のRootViewControllerは、次のように/ /ブロックを使用AFHTTPRequestOperation
して設定し、リクエストを作成します。downloadProgress
success
failure
AFHTTPRequestOperation *operation = [[InAppRageIAPHelper sharedHelper] prepareForDownload:productIdentifier];
[operation setDownloadProgressBlock:^(NSInteger bytesRead, NSInteger totalBytesRead, NSInteger totalBytesExpectedToRead) {
float percentDone = ((float)((int)totalBytesRead) / (float)((int)totalBytesExpectedToRead));
[(UIProgressView *)_hud.customView setProgress:percentDone];
_hud.labelText = [NSString stringWithFormat:@"%f",percentDone];
}];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
_hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"success.png"]];
[self performSelector:@selector(dismissHUD:) withObject:nil afterDelay:1.5];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
_hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"error.png"]];
}];
[operation start];
hudはMBProgressHUDです。モードを使用して進行状況の表示を強化することもできMBProgressHUDModeDeterminate
ます。