Ios 通知中心-显示和隐藏飞溅

Ios 通知中心-显示和隐藏飞溅,ios,swift,Ios,Swift,我有以下代码: 主视图控制器: override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(true) // register notification NotificationCenter.default.addObserver(self, selector: #selector(MainViewControler.StartUpdatingSplash), nam

我有以下代码:

主视图控制器:

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(true)
        // register  notification
        NotificationCenter.default.addObserver(self, selector: #selector(MainViewControler.StartUpdatingSplash), name: NSNotification.Name("updating.salestool"), 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"), object: nil)
    print("##### NOTIFICATION STEP: 2")
}
和Config.swift:

NotificationCenter.default.post(name: NSNotification.Name("updating.salestool"), 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.aviko.qbmobile.com"), object: nil)
            }
StartUpdatingSplash-运行splash

函数downloadImages-运行从internet下载照片的线程。 启动后的应用程序将显示splash(EZLoadingActivity),然后下载照片

我想在完成用于下载照片的所有线程后隐藏EZLoadingActivity(EZLoadingActivity.hide),例如通过运行finishUptatingSplash()函数。我该怎么做


My notificationcenter正确显示启动-我有一个问题,只需将其隐藏即可

在主异步队列中执行隐藏任务。

函数是否在MainViewControler类中下载图像

如果这是真的,您可以直接致电FinishUpdatingSplash:

    dispatchImagesGroup.notify(queue: .global()) {
            self.FinishUpdatingSplash()
        }
如果为false,则在所有下载任务完成后发布通知

    dispatchImagesGroup.notify(queue: .global()) {
              NotificationCenter.default.post(name: NSNotification.Name("FinishUpdatingSplashNotificationName"), object: nil
        }
您需要在MainViewControler中添加此通知的观察者,就像在StartUpdatingSplash中一样:

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

    //new code 

    NotificationCenter.default.addObserver(self, selector: #selector(MainViewControler.StartUpdatingSplash), name: NSNotification.Name("FinishUpdatingSplashNotificationName"), object: nil)
}

谢谢你的代码。此时会显示并隐藏飞溅。问题是,即使splash已被隐藏,文件仍会继续下载(即splash仍应可见)