Wednesday, January 10, 2024
HomeiOS Developmentswift - iOS - Posting notification known as twice

swift – iOS – Posting notification known as twice


I add an observer in a perform which I name on the beginning. It’s only initiated as soon as(I totally checked). On the safer aspect, I additionally take away observers earlier than I add observers. beneath is the perform

func setupLiveCycleNotifications() {
       
       SweeprClient.removeNotificationObservers()

       NotificationCenter.default.addObserver(self,
                                           selector: #selector(appMovedToBackground),
                                           title: UIApplication.didEnterBackgroundNotification, object: nil)
       NotificationCenter.default.addObserver(self,
                                           selector: #selector(appMovedToForeground),
                                           title: UIApplication.didBecomeActiveNotification, object: nil)

    }

In my UNIT TEST features, I attempted to check this characteristic. I provoke the category and I publish the notifications like proven beneath :


        let backgroundExpectation = self.expectation(description: "background expectation")
        let foregroundExpectation = self.expectation(description: "foreground expectation")
        Consumer.modules!.subscribe(module: "session", occasion: SessionProvider .Occasions.application_lifecycle.rawValue,
                                        tag: nil) { end result, tag in
            if end result == "background" {
                backgroundExpectation.fulfill()
            }

            if end result == "foreground" {
                foregroundExpectation.fulfill()
            }

        }
        NotificationCenter.default.publish(title: UIApplication.didEnterBackgroundNotification, object: nil)
        wait(for: [backgroundExpectation], timeout: Config.Timeout)
        NotificationCenter.default.publish(title: UIApplication.didBecomeActiveNotification, object: nil)
        wait(for: [foregroundExpectation], timeout: Config.Timeout)

The characteristic is to name again to my modules the place I fulfill the expectation however, the issue is each background and foreground are known as TWICE. I do not know why. I reset a number of occasions.I eliminated observers in lots of locations however, nothing works. Even when I remark the posting of notifications.No person calls my module. So, I’m positive I’m the one one who calls these notifications.

So, I kindly request to some one assist me with this problem

Thanks

  • I eliminated observers in a number of locations
  • I commented out the publish notifications however the expectation solely will get timed out, No person calls it



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments