@@ -51,26 +51,28 @@ if [ -z "$BUILT_PRODUCTS_DIR" ]; then
5151 exit 1
5252fi
5353
54- # In CocoaPods, SRCROOT/PRODUCT_NAME point to the Pods project, not the app.
55- # We need to find the actual app project root and app bundle.
54+ # In CocoaPods, SRCROOT/PRODUCT_NAME/BUILT_PRODUCTS_DIR refer to the pod
55+ # target, not the app. We need to resolve the real app project and . app bundle.
5656if [ -n " $PODS_ROOT " ]; then
57- # CocoaPods context: SRCROOT points to Pods/, not the app project.
58- # Resolve the real path to the app project (parent of Pods/).
57+ # App project root is the parent of the Pods/ directory
5958 APP_PROJECT_ROOT=$( cd " $PODS_ROOT " && cd .. && pwd)
6059
61- # Find the actual .app bundle in build products
62- APP_BUNDLE=$( find " $BUILT_PRODUCTS_DIR " -maxdepth 1 -name " *.app" -type d 2> /dev/null | head -1)
60+ # Pod's BUILT_PRODUCTS_DIR is a subdirectory (e.g., .../Debug-iphonesimulator/ByteHideMonitor/).
61+ # The app's .app bundle lives in the parent directory.
62+ APP_BUILD_DIR=$( dirname " $BUILT_PRODUCTS_DIR " )
63+ APP_BUNDLE=$( find " $APP_BUILD_DIR " -maxdepth 1 -name " *.app" -type d 2> /dev/null | head -1)
6364
6465 if [ -z " $APP_BUNDLE " ]; then
65- # .app not created yet — create directory so we can write monitor.sig
66+ # .app not built yet (clean build) — derive name from project directory
6667 APP_NAME=$( basename " $APP_PROJECT_ROOT " )
67- APP_BUNDLE=" ${BUILT_PRODUCTS_DIR } /${APP_NAME} .app"
68+ APP_BUNDLE=" ${APP_BUILD_DIR } /${APP_NAME} .app"
6869 mkdir -p " $APP_BUNDLE "
6970 fi
7071else
71- # SPM or manual build phase: standard Xcode context
72+ # SPM or manual: SRCROOT and PRODUCT_NAME refer to the app directly
7273 APP_PROJECT_ROOT=" ${SRCROOT} "
7374 APP_BUNDLE=" ${BUILT_PRODUCTS_DIR} /${PRODUCT_NAME} .app"
75+ mkdir -p " $APP_BUNDLE "
7476fi
7577
7678INFO_PLIST=" ${APP_BUNDLE} /Info.plist"
9496
9597# Priority 2: monitor-config.json
9698if [ -z " $TOKEN " ]; then
97- # Derive the app target name for subdirectory search
99+ # In CocoaPods, PRODUCT_NAME is the pod name; derive app name from project root
98100 if [ -n " $PODS_ROOT " ]; then
99101 APP_TARGET_NAME=$( basename " $APP_PROJECT_ROOT " )
100102 else
@@ -104,15 +106,9 @@ if [ -z "$TOKEN" ]; then
104106 CONFIG_PATHS=(
105107 " ${APP_PROJECT_ROOT} /monitor-config.json"
106108 " ${APP_PROJECT_ROOT} /${APP_TARGET_NAME} /monitor-config.json"
109+ " ${PROJECT_DIR} /monitor-config.json"
107110 )
108111
109- # Also check SRCROOT/PROJECT_DIR for SPM/manual context
110- if [ -z " $PODS_ROOT " ]; then
111- CONFIG_PATHS+=(
112- " ${PROJECT_DIR} /monitor-config.json"
113- )
114- fi
115-
116112 for CONFIG_PATH in " ${CONFIG_PATHS[@]} " ; do
117113 if [ -f " $CONFIG_PATH " ]; then
118114 # "apiToken" is the standard field name (matches SDK runtime)
0 commit comments