2016-01-04 133 views
2

后空闲我有一个视图控制器,将通过等待应用程序中断

if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) 
{ 
    [_locationManager requestWhenInUseAuthorization]; 
} 

这会触发“允许在您使用应用程序来访问你的位置?”请求访问的初始化定位服务 - 警报。

我用[self addUIInterruptionMonitorWithDescription:handler:]对此做出反应。我遇到以下问题:解除请求对话框后,ui-test不会继续。警报被驳回,但Xcode中等待应用程序成为空闲,但它看起来像应用程序空闲:

t = 67.35s    Wait for app to idle 

测试失败,因为应用程序被困在这里。如果我点击模拟器,Xcode记录。

t = 72.27s   Synthesize event 

并继续测试。

是否有原因,为什么Xcode试图等待应用程序?解决方法似乎是告诉Xcode用户界面已更改或事件发生。有没有办法触发这个?

+0

附加信息:解除推送通知警报确实很好... – Tobias

回答

9

提出警报后,您必须必须与接口交互。这是Xcode 7.2的一个已知错误。只需轻点应用程序就可以工作,但这是必需的。

addUIInterruptionMonitorWithDescription("Location Dialog") { (alert) -> Bool in 
    alert.buttons["Allow"].tap() 
    return true 
} 

app.buttons["Find Games Nearby?"].tap() 
app.tap() // need to interact with the app for the handler to fire 
XCTAssert(app.staticTexts["Authorized"].exists) 

查看my blog post了解更多信息。

+0

感谢您的帮助。事实上,我知道你的博客文章,并试图使用这个,但在中断监视器之后,窃听不起作用,因为Xcode认为,应用程序不是空闲的。 '测试失败 - 应用程序未能在30秒内停顿'测试将失败 – Tobias

+0

有趣。这听起来像你的应用中可能还有其他事情正在导致框架认为它没有响应。该方法中是否还有其他事情发生,也许在主线程中? –

+0

我在viewControllers的init中请求权限。在等待时,MKMapSnapshot完成(在给定的坐标上,而不是用户位置)并添加到UITableView。 TableView然后被重新加载。 Refreshcontrol停止。然后用户/测试点击“允许”,焦点返回到ViewController。 – Tobias