I cannot resume a paused downloading file with OkHttp
Also I use below code but cannot resume downloading
In hug file, that is necessary to resume the downloading
Also I use below code but cannot resume downloading
B4X:
#if b4i
#If OBJC
NSURLResponse *DownloadedResponse;
NSMutableData *DownloadedData;
NSString *FilePath;
NSURLConnection * connection2;
NSURLRequest *request;
- (void) cancel: (bool) on {
[connection2 cancel];
}
-(void)Download: (NSString *)FileUrl :(UILabel *)LabelToSet :(NSString *)Directory :(NSString *)FileName :(NSArray *)Headers :(NSArray *)Values
{
FilePath = [Directory stringByAppendingString: FileName];
DownloadedData = [[NSMutableData alloc] init];
NSURL *url = [NSURL URLWithString:FileUrl];
request = [NSURLRequest requestWithURL:url];
NSMutableURLRequest *mutableRequest = [request mutableCopy];
NSUInteger count = [Headers count];
for (NSUInteger i = 0; i < count; i++) {
NSString * key = [Headers objectAtIndex: i];
NSString * val = [Values objectAtIndex: i];
[mutableRequest addValue:val forHTTPHeaderField:key];
}
request = [mutableRequest copy];
NSURLConnection * connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
connection2 = connection;
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[DownloadedData appendData:data];
float res = ((100.0/DownloadedResponse.expectedContentLength)*DownloadedData.length)/100;
NSString * LabelText = [NSString stringWithFormat:@"%f", (res)];
NSString * LabelText2 = [NSString stringWithFormat:@"%d", [DownloadedData length]];
[self.bi raiseEvent:nil event:@"download_progress::" params:@[(LabelText),LabelText2]];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[DownloadedData writeToFile:FilePath atomically:YES];
[self.bi raiseEvent:nil event:@"download_complete" params:@[]];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[self.bi raiseEvent:nil event:@"download_error:" params:@[error.localizedDescription]];
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
DownloadedResponse = response;
}
#End If