0
afyncを使用してダウンロードを開始すると、afnetworkingの助けを借りてダウンロードしても、唯一その道を進んでいるが、私は再び同じダウンロード画面ブレークポイントに行くときも、画面上に来るが、それはここでは、ボタンのいずれかのタイトルまたはそのようなUIアクションダウンロード時にasyncをダウンロードしているときにVCを起動してもUIは変更されません。つまり、ボタンのタイトルです。
を変更doesntのこと
- (void) downloadByURL:(NSString *)URL
{
[self.progress setHidden:NO];
[self.btnsubscribe setUserInteractionEnabled:NO];
NSURL *url = [NSURL URLWithString:URL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
NSURLSessionDownloadTask *tasks=
[session downloadTaskWithRequest:request progress:nil destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {
//
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:[[[[NSString stringWithFormat:@"%@",self.ILModel.IssueID] stringByAppendingString:self.ILModel.Month] stringByAppendingString:self.ILModel.Year] stringByAppendingString:@".pdf"]];
return [NSURL URLWithString: path];
} completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nonnull filePath, NSError * _Nonnull error) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(void) {
[[NSData dataWithContentsOfURL:url] writeToFile:[filePath absoluteString] atomically:YES];
[self.progress setHidden:YES];
[KSToastView ks_showToast:@"Download Complete" duration:2.0f];
[self.btnsubscribe setBackgroundColor:[UIColor colorWithHexString:@"5BE4CA"]];
[self.btnsubscribe setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.btnsubscribe setTitle:@"View" forState:UIControlStateNormal];
[self.btnsubscribe setUserInteractionEnabled:YES];
});
}];
[session setDownloadTaskDidWriteDataBlock:^(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) {
int prog= (int)(totalBytesWritten * 100/totalBytesExpectedToWrite);
[self.progress setHidden:NO];
[self.btnsubscribe setTitle:@"Downloading" forState:UIControlStateNormal];
[KSToastView ks_showToast:[NSString stringWithFormat:@"Downloaded %lld %%",totalBytesWritten * 100/totalBytesExpectedToWrite] duration:1.0f];
[self performSelectorOnMainThread:@selector(setLoaderProgress:) withObject:[NSNumber numberWithFloat:(float)prog/100] waitUntilDone:NO];
NSLog(@"Progress… %lld",totalBytesWritten * 100/totalBytesExpectedToWrite);
}];
[tasks resume];
}
をダウンロードするための私のコードです
ありがとうございます...
をしかし、私はこの部分については取ってい –
...バックグラウンドスレッドのタスクの話ではないM:
は、以下のようにして、それを実行してください。 [セッションsetDownloadTaskDidWriteDataBlock:^(NSURLSession *セッション、NSURLSessionDownloadTask * downloadTask、int64_tのbytesWritten、int64_tのtotalBytesWritten、int64_tのtotalBytesExpectedToWrite){ int型PROG =(INT)(totalBytesWritten * 100/totalBytesExpectedToWrite)。 [self.progress setHidden:NO]; [self.btnsubscribe setTitle:@ "ダウンロード" forState:UIControlStateNormal];[KSToastView ks_showToast:[NSString stringWithFormat:@ "Downloaded%lld %%"、totalBytesWritten * 100/totalBytesExpectedToWrite]期間:1.0f]; }]; –
ちょうど私を試してみましょう –