欢迎访问啄木鸟家庭维修
首页 > 家修学院 > 生活百科 > ios远程看对方手机屏幕
找附近维修师傅,快速上门预约  

ios远程看对方手机屏幕

2022-11-14 来源:啄木鸟家庭维修 947

今天给大家带来的是基于苹果官方提供的UI测试框架实现的非越狱机器远程控制实现原理。

XCUITest

XCUITest是Aplle自Xcode7开始引入的自动化测试框架,而且在Xcode8中,原先的UIAutomation框架废弃无法再用。

相比较UIAutomation,XCUITest使用简便程度有了很大提高。

选择UITestCase,会生成一个Case文件如下:

#import

@interface testUI : XCTestCase

@end

@implementation testUI

- (void)setUp {

[super setUp];

// Put setup code here. This method is called before the invocation of each test method in the class.

// In UI tests it is usually best to stop immediately when a failure occurs.

self.continueAfterFailure = NO;

// UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.

[[[XCUIApplication alloc] init] launch];

// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.

}

- (void)tearDown {

// Put teardown code here. This method is called after the invocation of each test method in the class.

[super tearDown];

}

- (void)testExample {

// Use recording to get started writing UI tests.

// Use XCTAssert and related functions to verify your tests produce the correct results.

}

@end

根据提示在testExample部分修改添加代码。

此时可以使用xcode自带的录制功能,点击鼠标使得光标处于testExample的方法下,再点击红色的录制按钮。

项目会自动编译部署到指定的设备上(真机或模拟器均可),并自动启动。此时操作app的同时,Xcode会记录操作并自动转化成代码。

也可以手动根据自己需求调整或新增操作代码。

完毕后点击测试即可直接执行自动化测试。

设备控制

第一次执行测试会在设备端桌面生成一个类似xcuitesdemoUITests的APP,该APP无法执行执行,只能通过xcode的test启动。

启动时会有个瞬间的黑屏,然后app进入后台,同时启动待测APP,而后依次开始各项测试任务。

这里启动的哪个APP是由UITest项目的配置决定的,也就是说如果工程拥有多个APP,可以选择启动不同的APP。

当然也可以选择None,但启动测试的时候会出现以下的问题。

默认的XCUIApplication头文件中,只有如下2个方法:

@interface XCUIApplication : XCUIElement

/*!

* Launches the application. This call is synchronous and when it returns the application is launched

* and ready to handle user events. Any failure in the launch sequence is reported as a test failure

* and halts the test at this point. If the application is already running, this call will first

* terminate the existing instance to ensure clean state of the launched instance.

*/

- (void)launch;

/*!

* Terminates any running instance of the application. If the application has an existing debug session

* via Xcode, the termination is implemented as a halt via that debug connection. Otherwise, a SIGKILL

* is sent to the process.

*/

- (void)terminate;

但是可以从私有API的Header里能挖掘出比较多的方法。

+ (instancetype)appWithPID:(pid_t)processID;

- (void)dismissKeyboard;

- (BOOL)setFauxCollectionViewCellsEnabled:(BOOL)arg1 error:(id *)arg2;

- (void)_waitForViewControllerViewDidDisappearWithTimeout:(double)arg1;

- (void)_waitForQuiescence;

- (void)terminate;

- (void)_launchUsingXcode:(BOOL)arg1;

- (void)launch;

- (id)application;

- (id)deion;

- (id)lastSnapshot;

- (id)query;

- (void)clearQuery;

- (void)resolveHandleUIInterruption:(BOOL)arg1;

- (id)initPrivateWithPath:(id)arg1 bundleID:(id)arg2;

- (id)init;

通过InitPrivateWithPath方法可以以下述方法启动任意其他已安装的APP,并对其他APP进行操作。

比如下述代码可以启动safari,并打开http://mtc.baidu.com/

NSString *appBundleID = @”com.apple.mobilesafari”;

XCUIApplication* app = [[XCUIApplication alloc] initPrivateWithPath:nil bundleID:appBundleID];

[app launch];

[app.otherElements[@”URL”] tap];

[app typeText:@”mtc.baidu.comn”];

WebDriverAgent

WebDriverAgent(http://github.com/facebook/WebDriverAgent)是Facebook基于XCUITest推出的iOS的移动测试框架,支持目前市面上所有iOS9以上的设备。

该框架通过在设备端启动一个HTTP Server提供一系列API接受操作指令来代替固定的操作代码,除了启动应用、点击和滑动页面元素,WebDriverAgent还提供截图、页面元素查询等功能,iOS的appium测试框架就是基WebDriverAgent实现的。

远程控制iOS设备

基于上述技术,我们把功能具体化成一个Web服务。

通过轮询的方式获取当前屏幕内容,并将屏幕上的鼠标点击以及滑动操作转化成具体的操作指令,最终即可达到通过Web页面控制手机设备的效果。

免责声明:本网站转載内容均注明出处,转載是出于传递更多信息之目的,井不意味成其观点或证实其内容真实性。转载稿涉及版权等问题,请 立即联系网站编辑,我们会予以更改或删除相关文章,保证您的权利
预约一下·服务到家
请选择地址
      获取验证码

      好师傅推荐

      刘师傅

      刘师傅

      最近已有2483人购买 联系TA
      马老师

      马老师

      最近已有2955人购买 联系TA
      李师傅

      李师傅

      最近已有3025人购买 联系TA

      热门问题

      格力遥控器怎么切换摄氏华氏

      建议解决方法:正常情况下打开遥控器显示的状态都为摄氏度。转化为华氏度需要先关闭空调。然后同时按下空调遥控器上的模式键和减号键。这时空调遥控器上的温度就会显示为华氏度。

      8.0万次访问 查看详情

      海尔热水器显示f4是啥意思呢

      海尔热水器显示f4是啥意思?1、热水器的排气阀门出现故障,不能够正常的进行排气。2、温感探头由于故障问题未能正常工作。3、热水器的主板出现有焊接点松动的情况发生。4、电子膨胀阀周围产生大量的污垢,不能够正常工作。

      851次访问 查看详情

      电热水器安装法

      首先要先挂机、装水路必须选用PPR材料的卫生水管,水管连接应密封圈可靠连接可靠,安全阀应直接与热水器进水接口连接,再连接水管路;安装前必须辨别冷、热水接口位置,清理管内污物,并辨别其水路走向及管路连通的设施是否合理,确认正确后再安装。

      914次访问 查看详情

      燃气热水器能安装在橱柜里吗

      不可以。国家规范都要求燃气热水器放在通风、易查表、易检修的位置;对于燃气立管的要求也绝非不能封闭,而是不能与强电同一井道内,同时要求设置检修口;在规范中,燃气管甚至可以暗敷。

      637次访问 查看详情

      电视怎么安装呀?

      1、在装修的时候要留出挂电视的地方,用红砖水泥砌上,确保能把电视挂牢固。2、打开电视架的盒子,将显示平面放在水平的地方,用卷尺测量电视机后面螺丝孔两两之间的距离,确定买到合适的机体架。

      865次访问 查看详情
      没有合适的?想获取更多维修报价,试试“在线客服