活动指标和 UIApplication.sharedApplication()

activityIndicators and UIApplication.sharedApplication()

调用解锁设备不工作它打印 "unlockCalled" 很多次然后给出这个错误:

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

我哪里错了?

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()   
}

感谢@Alladinian

dispatch_async(dispatch_get_main_queue(), { () -> Void in 
    self.unlockDevice()
})