检测系统警报何时显示/将解除

时间:2014-10-29 16:30:55

标签: ios swift uialertview key-value-observing

我想检测系统alertView何时出现在屏幕上的应用内购买确认提醒。 我正在尝试将键值观察器添加到UIApplication中,但它不起作用。

UIApplication.sharedApplication().addObserver(self, forKeyPath: "windows", options: NSKeyValueObservingOptions.allZeros, context: &myContext)

2 个答案:

答案 0 :(得分:3)

这不是我想要的,但它对我有用。

NotificationCenter.addObserver(self, selector: "applicationWillResignActive", name: UIApplicationWillResignActiveNotification, object: nil)
NotificationCenter.addObserver(self, selector: "applicationDidBecomeActive", name: UIApplicationDidBecomeActiveNotification, object: nil)

func applicationDidBecomeActive()
{
    if Library.isPurchasing
    {
        Application.networkActivityIndicatorVisible = true
    }
}

func applicationWillResignActive()
{
    if Library.isPurchasing
    {
        Application.networkActivityIndicatorVisible = false
    }
}

答案 1 :(得分:0)

查看UIAlertViewDelegate文档。有willPresentAlertView:didPresentAlertView:alertView:willDismissWithButtonIndex:alertView:didDismissWithButtonIndex:等方法。