可以将应用程序从后台带到前台吗? [英] Possible to bring the app from background to foreground?

查看:87
本文介绍了可以将应用程序从后台带到前台吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行XCT UI测试时,可以在后台运行测试中的应用程序:

When running an XCT UI test it is possible to put the application under test in the background with:

XCUIDevice().pressButton(XCUIDeviceButton.Home)

它可以通过某种方式将应用程序带回前台(活动状态)没有重新启动应用程序?

It it possible in some way to bring the app back to foreground (active state) without relaunching the application?

推荐答案

Xcode 9更新:从Xcode 9开始,你现在可以在任何XCUIApplication上调用 activate()

Update for Xcode 9: Starting in Xcode 9, you can now simply call activate() on any XCUIApplication.

let myApp = XCUIApplication()
myApp.activate() // bring to foreground

https://developer.apple.com/documentation/xctest/xcuiapplication/2873317-activate

是的,是的。但是,你需要XCUIElement的私人标题(可通过Facebook的标题转储获得这里)。为了使应用程序前景化,您需要调用 resolve ,我相信它会解析元素的查询(对于应用程序来说,这意味着应用程序的前景)。

Yes, it is. But, you'll need XCUIElement's private headers (which are available via header dump from Facebook here). In order to foreground the app, you need to call resolve which I believe resolves the element's query (which for applications means foregrounding the app).

对于Swift,您必须将XCUIElement.h导入到桥接头中。对于Objective-C,您只需要导入XCUIElement.h。

For Swift, you'll have to import the XCUIElement.h into your bridging header. For Objective-C you'll just need to import XCUIElement.h.

随着应用程序的背景:

Swift:

XCUIApplication().resolve()

Objective-C

Objective-C

[[XCUIApplication new] resolve];

如果这是你需要的唯一功能,你可以写一个快速的ObjC类别。

If this is the only functionality you need, you could just write a quick ObjC category.

@interface XCUIElement (Tests)
- (void) resolve;
@end

如果您需要启动/解析其他应用。 Facebook在此通过跳板举一例。

If you need to launch / resolve another app. Facebook has an example of that here by going through the Springboard.

这篇关于可以将应用程序从后台带到前台吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆