0

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 functionand 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
            }
        })
Newbie
  • 360
  • 3
  • 19
  • First divide your problem into smaller ones. - You need to write a custom table cell class and its view - Add a progress view to it and connect it with your custom class - Increment each progress bar with their respective data. – Khushneet Jan 15 '20 at 12:44
  • @Khushneet I have already created custom table cell class. attached picture I have already designed it. Only issue is how I observe progress bar? because Alamofire progress bar is in Dataprovider.class and in view controller I am using callback function to access web service. – Newbie Jan 15 '20 at 12:53
  • I haven't use Alamofire, but on searching it on google I found similar question https://stackoverflow.com/questions/33827438/progress-of-a-alamofire-request There are many other questions/answers on StackOverflow itself. You might need to go through all. – Khushneet Jan 15 '20 at 13:00

0 Answers0