Skip to content

Instantly share code, notes, and snippets.

@jkereako
Last active July 15, 2025 17:10
Show Gist options
  • Save jkereako/3825e8c8d0d0150e85a9e334d762a584 to your computer and use it in GitHub Desktop.
Save jkereako/3825e8c8d0d0150e85a9e334d762a584 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# push
#
# Sends a push notification to the specified iOS simulator.
set -Eeuo pipefail
readonly SCRIPT_NAME=${0##*/}
readonly APP_BUNDLE_ID="com.your.app.bundle"
# Print out error messages to stderr.
function err() {
echo -e "\033[0;31mERROR: $@\033[0m" >&2;
}
function check_file() {
local file="$1"
if [[ ! -f $file ]]; then
err "File not found: $file"
exit 1
fi
if [[ ! -r $file ]]; then
err "File not readable: $file"
exit 1
fi
if [[ ! -s $file ]]; then
err "File is empty: $file"
exit 1
fi
}
#-- Main
function main() {
if [[ $# -ne 1 ]]; then
err "Usage: $SCRIPT_NAME /path/to/payload.apns"
exit 1
fi
check_file "$1"
device_id=$(xcrun simctl list | grep "booted" -i | grep -oEi '[a-f0-9-]{36}')
if [[ -z $device_id ]]; then
err "No simulators found."
exit 1
fi
# Check if there are multiple devices found, echo that to the user, and select the first one
if [[ $(echo "$device_id" | wc -l) -gt 1 ]]; then
echo "Multiple simulators found:"
echo "$device_id"
echo "Using the first one."
fi
echo "Sending remote notification to device: $device_id"
xcrun simctl push "$device_id" "$APP_BUNDLE_ID" "$1"
}
main "$@"
@jkereako
Copy link
Author

jkereako commented Jul 14, 2025

Description

Sends a fake remote notification to the booted simulator. If you have multiple simulators running, this script will choke.

APNs payload

Below is an example of a APNs payload. Save it as a .apns file and use this to send the push notification.

{
  "aps": {
    "category": "SomeCategory",
    "alert": {
      "title" : "Doorbell",
      "body": "Johnny Appleseed rang your doorbell",
    },
    "badge": 3,
    "sound": "chime.aiff"
  },
  "url": "https://www.goog.com"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment