I am designing download Services for all webServices to set and read data offline mode. I am saving all JSON response to SQLite to reuse when there is no internet coverage or offline mode.
My webServices are dependent to each other like Appointment
-> AppointmentDetail
so on.
On selection of date func appointmentCall
executes and inside more function.
I have DataProvider.class
which has Alamofire function
and all webServices callback function call in DownloadViewController
. I am doing JSON response and retrieving with success from SQLite
.
Issue is at design perspective, using tableview xib for displaying download progress thing. One date Appointment -- can be many appointments. I need to show progress bar with appointmentname.
I haven't found any calculation thing to track download.
My webServices code and image for download design progress.
func appointmentCall(_ someDateTime:Date) {
DataProvider.main.serviceGetAppointment(date: someDateTime, callback: {success, result in
do{
if(success){
let decoder = JSONDecoder()
let response = try decoder.decode(ResponseData.self, from: result! as! Data)
self.Appdata = response.appointments
for appID in self.Appdata! {
self.appointmentDetail(AppId: appID.id ?? 0)
}
return true
}else{
return false
}
}catch let error {
DataProvider.main.token = nil
print(error as Any)
return false
}
})
}
func appointmentDetail(AppId: Int){
DataProvider.main.serviceGetAppointmentDetail(Id: AppId ?? 0, callback: {success, result in
do{
if(success){
let decoder = JSONDecoder()
let response = try decoder.decode(AppointmentDetail.self, from: result! as! Data)
self.AppDetailData = response
for firmParam in (self.AppDetailData?.sectionList ?? []) {
for firmItem in firmParam.items! {
if firmItem.actionParamData != nil {
let str = firmItem.actionParamData
let param = str?.components(separatedBy: ":")
let final = param![1].replacingOccurrences(of: "}", with: "")
let fmId = final.components(separatedBy: ",")
let frmId = fmId[0]
self.firmDetails(actionParamData: Int(frmId) ?? 0)
}
//pdf download
if firmItem.actionUrl != nil {
self.downloadPDFTask(pdfURL: firmItem.actionUrl ?? "")
}
// unit services download
if firmItem.unitId != nil {
self.unitData(id: firmItem.unitId ?? 0)
self.unitDataHistory(id: firmItem.unitId ?? 0)
self.unitDataImages(id: firmItem.unitId ?? 0)
}
}
}
return true
}else{
return false
}
}catch let error {
print(error as Any)
return false
}
})