-
-
Save jkereako/3825e8c8d0d0150e85a9e334d762a584 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.