Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

triffek

macrumors newbie
Original poster
Jun 19, 2018
1
0
I have this code:

MainViewControler:


Code:
override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(true)
        // register  notification
        NotificationCenter.default.addObserver(self, selector: #selector(MainViewControler.StartUpdatingSplash), name: NSNotification.Name("updating.salestool.bla.pl"), object: nil)
    }

    @objc func StartUpdatingSplash() {
    DispatchQueue.global().async {
        EZLoadingActivity.show("LoadingMessage4".localized(), disableUI: true)
    }
    print("##### NOTIFICATION STEP: 1")
}

@objc func FinishUpdatingSplash() {
    DispatchQueue.global().async {
        EZLoadingActivity.hide()
    }
    NotificationCenter.default.removeObserver(self, name: Notification.Name("updating.salestool.bla.pl"), object: nil)
    print("##### NOTIFICATION STEP: 2")
}

and Config.swift:


Code:
NotificationCenter.default.post(name: NSNotification.Name("updating.salestool.bla.pl"), object: nil)

let dispatchImagesGroup = DispatchGroup()
                dispatchImagesGroup.enter()
                DispatchQueue.global().async {
                    self.downloadImages(toDownloads: jsonData, savedURL: FileFolders.GET_PHOTO.rawValue, parametr: FileFolders.GET_PHOTO.rawValue)
                    dispatchImagesGroup.leave()
                }

                dispatchImagesGroup.enter()
                DispatchQueue.global().async {
                    self.downloadImages(toDownloads: jsonData, savedURL: FileFolders.GET_INSPIRATION_PHOTO.rawValue , parametr: FileFolders.GET_INSPIRATION_PHOTO.rawValue)
                    dispatchImagesGroup.leave()
                }

                dispatchImagesGroup.enter()
                DispatchQueue.global().async {
                    self.downloadImages(toDownloads: jsonData, savedURL: FileFolders.GET_PACKSHOT.rawValue , parametr: FileFolders.GET_PACKSHOT.rawValue)
                    dispatchImagesGroup.leave()
                }


                dispatchImagesGroup.enter()
                DispatchQueue.global().async {
                    self.downloadImages(toDownloads: jsonData, savedURL: (AppGlobalManager.sharedManager.loggedUser?.selectedLanguage)! + "/" + FileFolders.GET_TIPS_SLIDES.rawValue, parametr: FileFolders.GET_TIPS_SLIDES.rawValue)
                    dispatchImagesGroup.leave()
                }

                dispatchImagesGroup.enter()
                DispatchQueue.global().async {
                    self.downloadImages(toDownloads: jsonData, savedURL: (AppGlobalManager.sharedManager.loggedUser?.selectedLanguage)! + "/" + FileFolders.GET_LEAFLETS_SLIDES.rawValue, parametr: FileFolders.GET_LEAFLETS_SLIDES.rawValue)
                    dispatchImagesGroup.leave()
                }

                dispatchImagesGroup.enter()
                DispatchQueue.global().async {
                    self.downloadImages(toDownloads: jsonData, savedURL: (AppGlobalManager.sharedManager.loggedUser?.selectedLanguage)! + "/" + FileFolders.GET_CONCEPTS_SLIDES.rawValue, parametr: FileFolders.GET_CONCEPTS_SLIDES.rawValue)
                    dispatchImagesGroup.leave()
                }

                dispatchImagesGroup.enter()
                DispatchQueue.global().async {
                    self.downloadLeafletsPDF(toDownloads: jsonData, savedURL: (AppGlobalManager.sharedManager.loggedUser?.selectedLanguage)! + "/" + FileFolders.GET_LEAFLETS_PDF.rawValue)
                    dispatchImagesGroup.leave()
                }

                dispatchImagesGroup.notify(queue: .global()) {
                NotificationCenter.default.addObserver(self, selector: #selector(MainViewControler.FinishUpdatingSplash), name: NSNotification.Name("updating.salestool.bla.pl"), object: nil)
            }

StartUpdatingSplash - runs the splash.

Function downloadImages - runs the thread for downloading photos from the internet. The application after launch displays splash (EZLoadingActivity) and then downloads the photos.

I would like to hide EZLoadingActivity (EZLoadingActivity.hide) after finishing all these threads used to download photos, for example by running the FinishUpdatingSplash () function. How can I do this?

My notificationcenter correctly displays the splash - I have a problem just hide it :(
 
Last edited:

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
You should only be updating UI on the main thread, not the global background thread. In the place where you ar registering for the Finish notification you should post the Finish notification (on the main thread).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.