Logo
iOS SDK Obfuscation
To initialise the SDK add the below line of code with the public key you retrieved from Sense client panel. If you don't have a public key create new one and call that below function.
Summary
The obfuscation implementation code is available on the Sense Server. Before running obfuscation on the Swift project, please review the code carefully for any syntax errors and ensure that standard coding practices are followed. The obfuscation process will programmatically obfuscate the project. Therefore, it is important to maintain proper coding standards.
Obfuscation Process
  1. The Sense team will provide a bash script for obfuscation.
  2. Create a .sh file inside the project directory (for example: sense_obfuscator.sh).
  3. In the obfuscator script, add the Basic Authentication credentials by pasting the Public Key and Secret Key provided in the Client Panel.
  4. Open the terminal and navigate to the project directory.
    Run the following command:
    copy-icon
    copy-icon
    sh sense_obfuscator.sh
  5. The Sense script will take responsibility for the process, obfuscate the project files, and display a completion indicator once the process is finished.
  6. Then check the final obfuscator project files
Note
Please ensure that a backup of the project is taken before running the obfuscation process. The obfuscator will also create a backup before executing the obfuscation.
Shell Script
copy-icon
copy-icon
#!/bin/bash
set -euo pipefail


echo "๐Ÿ”’ ================================================"
echo "๐Ÿ”’  DOWNLOAD & RUN OBFUSCATOR"
echo "๐Ÿ”’ ================================================"


# ---------------------------------------------------
# 1. Detect Project Directory
# ---------------------------------------------------
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
TEMP_DIR="$PROJECT_DIR/.obf_temp"
mkdir -p "$TEMP_DIR"


OBF_BIN="$TEMP_DIR/obfuscator.bin"
REMOTE_URL="https://strctl.gosense.ai/v1/sense-protect-ios-sdk"


echo "๐Ÿ“‚ Project Directory : $PROJECT_DIR"
echo "๐Ÿ“ Temp Directory    : $TEMP_DIR"


# ---------------------------------------------------
# 2. Download Obfuscator
# ---------------------------------------------------
echo "๐Ÿ“ก Downloading obfuscator..."
AUTH_HEADER=$(printf "%s:%s" "<Publick key>" "<Private key>" | base64)


curl -fSL  -H "Authorization: Basic $AUTH_HEADER"  -o "$OBF_BIN"  "$REMOTE_URL" || {
   echo "โŒ Download failed"
   rm -rf "$TEMP_DIR"
   exit 1
}


echo "๐Ÿ”“ Removing macOS quarantine..."
xattr -dr com.apple.quarantine "$OBF_BIN"


chmod +x "$OBF_BIN"


# ---------------------------------------------------
# 3. Run Obfuscator
# ---------------------------------------------------
echo "๐Ÿš€ Running Swift Obfuscator..."
"$OBF_BIN" "$PROJECT_DIR" --in-place --force || {
   echo "โŒ Obfuscation failed"
   rm -rf "$TEMP_DIR"
   exit 1
}
echo "๐ŸŽ‰ Obfuscation Complete!"


# ---------------------------------------------------
# 4. Delete Temp Directory (including .bin)
# ---------------------------------------------------
echo "๐Ÿงน Cleaning temp directory..."
rm -rf "$TEMP_DIR"
echo "โœ… Obfuscator binary deleted"


echo "๐Ÿ”’ ================================================"
echo "โœ” All done โ€” no leftover binaries"
echo "๐Ÿ”’ ================================================"
exit 0