Using a Raspberry Pi to end an iPhone phone call

Raspberry Pi controls relay to mimic iPhone user clicking headphone switch

Headphone breakout switch

A user can end a phone call by clicking the headphone switch.
A program can end a phone call by closing a headphone breakout switch.



I made a prototype.

Prototype system

The system has several parts

Phoney app, request_web_service_end_call branch

It has a button to call a phone number.

Phoney XCUITest

XCUITest runs the test from Swift on iOS. It needs a way to ask the raspberry pi to end the call. I didn't see an easy way to issue a system call or spawn a process.
So XCUITest makes an http request to an external web server, ask it to close switch.


Making a phone call requires a device, not a simulator.

Raspberry Pi

The Raspberry Pi runs a web service and connects to a relay board.


runs on the local wifi network.

Server security

Currently the prototype service runs on the local network, and is not very secured.
By default an iOS app that talks with a web service requires https and TLS 1.2.
Apparently XCUITest doesn't require this, at least when talking with a service on the local network.


The raspberry pi connects to a relay

The relay acts like the headset "end call" switch, momentarily shorting the headset microphone contact to ground.

Cable, relay to breakout switch

Coaxial splitter, 1 female to 2 males (female unused)

Headphone breakout switch

Making an iPhone Headphone Breakout Switch


A standard iPhone wired headphone with a 4 connector plug.

Cable, breakout switch to phone

Connects breakout switch to phone. 3.5 mm 4 conductor male to 3.5 mm 4 conductor male

Test Flow

Test failure

The test adds a UIInterruptionMonitor, then interacts with the app UI via swipeUp or tap.
Without this, the iOS phone call alert handler doesn't fire.
But with it, the test usually ends with error ~ "Application for Target Application 0x1c40af060 is not foreground.".
I fixed the failure by switching to springboard. That made this approach obsolete.


XCUITest iOS app phone call


Phoney is an iOS application to experiment with testing phone calls.

request_web_service_end_call branch

Uses XCUITest to make an http request to an external web server, asks it to end call by closing switch.

master branch

Uses XCUITest with Springboard to tap End call button.


Make a simple Python flask web service to read and write Raspberry Pi GPIO.


PiFace Digital 2

purchased from Vetco Electronics

Headphone breakout switch

Making an iPhone Headphone Breakout Switch