Shake gesture not working iOS

Viewed 1337

I have used collectionView and also implemented pull to sync (pull_Down_To_Get_Data_From_Server) in my ViewController(named : "DashboardViewController"). I tried the shake gesture code(given below) in my DashboardViewController and its not working but similar code is working in another viewController of same app.

I used the canBecomeFirstResponder in viewDidLoad in first try and in viewDidAppear secondly but it was also useless.

Requirement: Actualy i want to know the cases(if any) in which ".motionShake" event do not trigger directly and we have to implement another way? Also that i did not find anything fruitful on google. Image of storyboard may help in understanding all the utilities used

override func viewDidLoad() {
 // call super
    super.viewDidLoad()
    self.becomeFirstResponder() // for shake gesture detection
}

// it will make first responder to detect shake motion event
override var canBecomeFirstResponder: Bool {
    get {
        return true
    }
}

// get detection of shake motion event
override func motionEnded(_ motion: UIEventSubtype, with event: UIEvent?) {
    if motion == .motionShake 
    {
        print("Shake detected")
    }
}
1 Answers
Related