Hello Experts,
We would need to show the Estimated time to complete the caching of map. This can be done if we have some reference on how much is already downloaded to the device and the total size of the map.
For the same, i have written code something like below, but not getting how can i calculate/get how much has been downloaded.
-(void) cacheBasemapParameters:(AGSExportTileCacheParameters *)params withSteps:(int) steps
{
[self deleteExistingTPKFile];
// Use a weak variable for self within the blocks
__weak EsriMapViewController *weakSelf = self;
// temp file
NSURL *tempFileDirectoryUrl = [[NSFileManager.defaultManager temporaryDirectory] URLByAppendingPathComponent:NSProcessInfo.processInfo.globallyUniqueString];
NSURL* docDirectoryURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory
inDomains:NSUserDomainMask] lastObject];
[NSFileManager.defaultManager createDirectoryAtURL:tempFileDirectoryUrl withIntermediateDirectories:YES attributes:nil error:nil];
NSString *extension = @".tpk";
if (self.tileCacheTask.mapServiceInfo.exportTileCacheCompactV2Allowed)
{
extension = @".tpkx";
}
NSURL *tempFileUrl = [docDirectoryURL URLByAppendingPathComponent:[@"myTileCache" stringByAppendingString:extension]];
// Kick-off operation
AGSExportTileCacheJob *job = [self.tileCacheTask exportTileCacheJobWithParameters:params downloadFileURL:tempFileUrl];
self.cacheJob = job;
[self.cacheJob startWithStatusHandler:^(AGSJobStatus status) {
//Print the job status
DLog(@"%d", status);
//NSArray *allMessages = [userInfo objectForKey:@"messages"];
//Display download progress if we are fetching result
/*if (status == 3) {
NSNumber* totalBytesDownloaded = userInfo[@"AGSDownloadProgressTotalBytesDownloaded"];
NSNumber* totalBytesExpected = userInfo[@"AGSDownloadProgressTotalBytesExpected"];
if(totalBytesDownloaded!=nil && totalBytesExpected!=nil){
double dPercentage = (double)([totalBytesDownloaded doubleValue]/[totalBytesExpected doubleValue]) * 100;
[weakSelf showProgressWithMessage:[NSString stringWithFormat:@"%@\n%.2f%% %@", statusMessageTitle, dPercentage, [weakSelf.dataSource textValueForKey:@"DownloadStatus"]]];
}
}else if ( allMessages.count) {
[weakSelf showProgressWithMessage:[self extractMostRecentMessage:allMessages]];
} */
} completion:^(AGSTileCache * _Nullable result, NSError * _Nullable error) {
if (error){
[weakSelf hideProgress];
//alert the user
[ViewUtils showSimpleAlertWithTitle:[self.dataSource textValueForKey:@"Error"]
message:[self.dataSource textValueForKey:@"BasemapDownloadError"]
cancelButtonTitle:[self.dataSource textValueForKey:@"Ok"]];
// no need to proceed further if basemaps cannot be downloaded.
}
else{
DLog(@"Successfully downloaded basemap");
// start downloading feature layers
if(weakSelf.featureLayersToCache.count > 0){
// delete all cached feature layers
[self deleteCachedGeodatabases];
[self.gdbFeatureLayerMap removeAllObjects];
}
[weakSelf cacheNextFeatureLayer];
}
}];
}
Any idea on how to get it done?
Thanks,
Ajitesh