1

Calling unlock device is not working it prints "unlockCalled" a lot of times and then gives this error:

2016-03-27 14:20:45.976 xxx[1002:57886] -[UIApplication endIgnoringInteractionEvents] called without matching -beginIgnoringInteractionEvents. Ignoring.

Where am I going wrong?

var activityIndicator = UIActivityIndicatorView()

func lockDevice(){print("lockCalled")
    activityIndicator = UIActivityIndicatorView(frame: self.view.frame)
    activityIndicator.backgroundColor = UIColor(white: 1.0, alpha: 0.5)
    activityIndicator.center = self.view.center
    activityIndicator.hidesWhenStopped = true
    activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray
    view.addSubview(activityIndicator)
    activityIndicator.startAnimating()
    UIApplication.sharedApplication().beginIgnoringInteractionEvents()
}
func unlockDevice(){
    print("unlockCalled")
    activityIndicator.stopAnimating()
    UIApplication.sharedApplication().endIgnoringInteractionEvents()   
}
Vatsal Manot
  • 17,695
  • 9
  • 44
  • 80
Kaan Karay
  • 81
  • 8
  • Well, the error message is pretty self-explanatory... where (and when) are you calling these functions ? – Alladinian Mar 27 '16 at 13:12
  • i lockDevice() then retrieve data from web in like 5-6 seconds then i unlockDevice() but activityIndicator won't go away and it still ignore my events @Alladinian – Kaan Karay Mar 27 '16 at 13:22
  • You can set a breakpoint on your callback to inspect the issue. Also, make sure that `unlockDevice()` is called on the main thread. – Alladinian Mar 27 '16 at 14:25
  • 1
    oh god i tried unlockDevice()'s inside code in main thread but it didn't work dispatch_async(dispatch_get_main_queue(), { () -> Void in self.unlockDevice()}) this saved me thanks @Alladinian – Kaan Karay Mar 27 '16 at 15:50

1 Answers1

0

Thanks to @Alladinian

dispatch_async(dispatch_get_main_queue(), { () -> Void in 
    self.unlockDevice()
})
Kaan Karay
  • 81
  • 8