Skip to main content
Control your iPhone’s lock state programmatically.

Lock

Lock the device screen:
phone.lock()
This is equivalent to pressing the side button to turn off the screen.

Unlock

Unlock the device:
# Unlock (if no passcode)
phone.unlock()

# Unlock with passcode
phone.unlock(passcode="123456")

Parameters

ParameterTypeDefaultDescription
passcodestr | NoneNoneDevice passcode if required
If the device has a passcode and you don’t provide it, the unlock will fail. Face ID and Touch ID are not supported through the API.

Check Lock State

Check if the device is locked via the status endpoint:
status = client.status()

if status.screen_locked:
    print("Device is locked")
    phone.unlock(passcode="123456")
else:
    print("Device is unlocked")

Examples

Safe Unlock

# Check status before unlocking
status = client.status()

if status.screen_locked:
    phone.unlock(passcode="123456")
    time.sleep(0.5)  # Wait for unlock animation

# Now interact with the device
phone.open_app("Safari")

Lock After Task

# Do some work
phone.open_app("Notes")
time.sleep(1)
phone.type_text("Important note")
time.sleep(0.5)

# Lock when done
phone.lock()

Unlock and Verify

phone.unlock(passcode="123456")
time.sleep(0.5)

# Verify unlocked
status = client.status()
if not status.screen_locked:
    print("Successfully unlocked")
else:
    print("Unlock failed")

Security Considerations

Never hardcode passcodes in your code. Use environment variables or secure credential storage:
import os

passcode = os.environ.get("DEVICE_PASSCODE")
phone.unlock(passcode=passcode)
Remember that iOS will auto-lock the device after a period of inactivity. For long-running scripts, periodically interact with the device or check lock status.
iOS limits incorrect passcode attempts. Be careful with automated unlock attempts to avoid triggering security lockouts.

Next Steps