2

I wanna build a automatic iOS app test framework. I can record the touch event by IOHIDFamily, so any way to replay this?

I tried GSEvent like this

void sendclickevent(){     
    mach_port_t thePortOfApp = GSCopyPurpleNamedPort("com.fuckyou.fuck");     

    GSEventRecord header;     
    GSHandInfo click;     
    GSPathInfo pathInfo = {2,2,2,1,1,{50,50}, NULL};     

    bzero(&header, sizeof(header));     
    bzero(&click, sizeof(click));     

    header.type = kGSEventHand;     
    header.subtype = kGSEventSubTypeUnknown;     
    header.location.x = 50;     
    header.location.y = 50;     
    header.windowLocation.x = 50;     
    header.windowLocation.y = 50;     
    header.infoSize = sizeof(GSHandInfo)+sizeof(GSPathInfo);     
    header.timestamp = mach_absolute_time();     

    click.type = kGSHandInfoTypeTouchDown;     
    click.deltaX = 1;     
    click.deltaY = 1;     
    click.pathInfosCount = 1;     

    struct    
    {     
        GSEventRecord record;     
        GSHandInfo hand;     
        GSPathInfo path;     
    } record = {header, click, pathInfo};     

    GSSendEvent(&record, thePortOfApp);     
}

thePortOfApp return Non-Zero. But at end of this function, such as press a button, nothing happpend. So something wrong? or I need another way to send touch event to iOS UI?

Kevin Lee
  • 272
  • 3
  • 13

1 Answers1

1

Take a look some other questions related to sending events outside of your app:

Use GSEvent to send touch event,but it's invalid

Using GraphicsServices.h/GSEvent as well as compiling CLI iPhone tools with Xcode

How to send a touch event to iPhone OS?

Simulating System Wide Touch Events on iOS

Notes

1) I believe you should send touchDown first and touchUp second to get a click.

2) Most of code which I saw on this subject used GSGetPurpleSystemAppPort() which allows to send system wide events (vs GSCopyPurpleNamedPort).

I believe GSCopyPurpleNamedPort just does usual bootstrap_look_up port. So, it will find a port, even if it's no a purple port (which is most likely true for "com.fuckyou.fuck")

Community
  • 1
  • 1
Victor Ronin
  • 21,310
  • 16
  • 85
  • 171