diff --git a/ios/build.zsh b/ios/build.zsh
index 59fbf46..dfc2e79 100755
--- a/ios/build.zsh
+++ b/ios/build.zsh
@@ -41,6 +41,22 @@ else
fi
function cleanup_build {
+ # 1.8. Update package.json version (prevent App Store version conflict)
+ echo "1.8. Updating package.json version..."
+ if [ -n "$APP_VERSION" ]; then
+ PACKAGE_JSON="$REPO_DIR/package.json"
+ # Use node to update version in package.json
+ node -e "
+ const fs = require('fs');
+ const pkg = JSON.parse(fs.readFileSync('$PACKAGE_JSON', 'utf8'));
+ pkg.version = '$APP_VERSION';
+ fs.writeFileSync('$PACKAGE_JSON', JSON.stringify(pkg, null, 2) + '\n');
+ "
+ echo " ✅ Set version to $APP_VERSION"
+ else
+ echo " ⚠️ APP_VERSION not set in .env"
+ fi
+
# 2. Prebuild (Generate ios directory)
echo "2. Running Expo Prebuild..."
# Clean old ios folder to remove old entitlements/AppClip targets
@@ -55,16 +71,50 @@ function cleanup_build {
pod install
cd ..
- # 4. Signing (Manual Step)
- echo "4. Opening Xcode for Signing..."
+ # 4. Signing (Automated)
+ echo "4. Configuring Xcode Signing..."
XCODE_PROJ="ios/${APP_NAME}.xcodeproj"
- # Fallback search if variable name logic differs
if [ ! -d "$XCODE_PROJ" ]; then
XCODE_PROJ=$(find ios -name "*.xcodeproj" | head -n 1)
fi
+ PBXPROJ="$XCODE_PROJ/project.pbxproj"
- open "$XCODE_PROJ"
- read
+ # Set DEVELOPMENT_TEAM in pbxproj
+ if [ -n "$DEVELOPMENT_TEAM" ]; then
+ echo " Setting DEVELOPMENT_TEAM=$DEVELOPMENT_TEAM"
+ sed -i '' "s/PRODUCT_BUNDLE_IDENTIFIER = /DEVELOPMENT_TEAM = $DEVELOPMENT_TEAM; PRODUCT_BUNDLE_IDENTIFIER = /g" "$PBXPROJ"
+ sed -i '' "s/DEVELOPMENT_TEAM = \"\";/DEVELOPMENT_TEAM = $DEVELOPMENT_TEAM;/g" "$PBXPROJ"
+ sed -i '' "s/DEVELOPMENT_TEAM = ;/DEVELOPMENT_TEAM = $DEVELOPMENT_TEAM;/g" "$PBXPROJ"
+ fi
+
+ # Create/Update entitlements file with App Group
+ ENTITLEMENTS_FILE="ios/${APP_NAME}/${APP_NAME}.entitlements"
+ if [ -n "$APP_GROUP" ]; then
+ echo " Setting APP_GROUP=$APP_GROUP"
+ cat > "$ENTITLEMENTS_FILE" << EOF
+
+
+
+
+ aps-environment
+ production
+ com.apple.security.application-groups
+
+ ${APP_GROUP}
+
+
+
+EOF
+ if ! grep -q "CODE_SIGN_ENTITLEMENTS" "$PBXPROJ"; then
+ sed -i '' "s/DEVELOPMENT_TEAM = $DEVELOPMENT_TEAM;/DEVELOPMENT_TEAM = $DEVELOPMENT_TEAM; CODE_SIGN_ENTITLEMENTS = ${APP_NAME}\\/${APP_NAME}.entitlements;/g" "$PBXPROJ"
+ fi
+ fi
+
+ echo "✅ Signing configured automatically"
+
+ # (Old manual step - commented out)
+ # open "$XCODE_PROJ"
+ # read
}
case $1 in
@@ -84,6 +134,7 @@ xcodebuild -workspace "$WORKSPACE" \
-configuration Release \
-archivePath "$BUILD_DIR/${APP_NAME}.xcarchive" \
-allowProvisioningUpdates \
+ DEVELOPMENT_TEAM="$DEVELOPMENT_TEAM" \
archive 2>&1 | tee "$BUILD_DIR/build.log"
# アーカイブ成功確認
diff --git a/ios/preview.zsh b/ios/preview.zsh
index 070c575..f89d316 100755
--- a/ios/preview.zsh
+++ b/ios/preview.zsh
@@ -34,6 +34,21 @@ else
echo "⚠️ Warning: $ASSETS_DIR not found"
fi
+# 1.8. Update package.json version (prevent App Store version conflict)
+echo "1.8. Updating package.json version..."
+if [ -n "$APP_VERSION" ]; then
+ PACKAGE_JSON="$REPO_DIR/package.json"
+ node -e "
+ const fs = require('fs');
+ const pkg = JSON.parse(fs.readFileSync('$PACKAGE_JSON', 'utf8'));
+ pkg.version = '$APP_VERSION';
+ fs.writeFileSync('$PACKAGE_JSON', JSON.stringify(pkg, null, 2) + '\n');
+ "
+ echo " ✅ Set version to $APP_VERSION"
+else
+ echo " ⚠️ APP_VERSION not set in .env"
+fi
+
# 2. Prebuild (Generate ios directory)
echo "2. Running Expo Prebuild..."
# Clean old ios folder to remove old entitlements/AppClip targets
@@ -48,25 +63,62 @@ cd ios
pod install
cd ..
-# 4. Signing (Manual Step)
-echo "4. Opening Xcode for Signing..."
+# 4. Signing (Automated)
+echo "4. Configuring Xcode Signing..."
XCODE_PROJ="ios/${APP_NAME}.xcodeproj"
-# Fallback search if variable name logic differs
if [ ! -d "$XCODE_PROJ" ]; then
XCODE_PROJ=$(find ios -name "*.xcodeproj" | head -n 1)
fi
+PBXPROJ="$XCODE_PROJ/project.pbxproj"
-open "$XCODE_PROJ"
-echo "========================================================"
-echo " [ACTION REQUIRED] "
-echo " Xcode opened ($XCODE_PROJ)."
-echo " 1. Go to 'Signing & Capabilities' tab."
-echo " 2. Select your Team."
-echo " 3. Verify 'App Clip' target is gone."
-echo " 4. Ensure no red errors exist."
-echo " Press ENTER here once you are done to continue building."
-echo "========================================================"
-read
+# Set DEVELOPMENT_TEAM in pbxproj
+if [ -n "$DEVELOPMENT_TEAM" ]; then
+ echo " Setting DEVELOPMENT_TEAM=$DEVELOPMENT_TEAM"
+ # Add DEVELOPMENT_TEAM to all build configurations
+ sed -i '' "s/PRODUCT_BUNDLE_IDENTIFIER = /DEVELOPMENT_TEAM = $DEVELOPMENT_TEAM; PRODUCT_BUNDLE_IDENTIFIER = /g" "$PBXPROJ"
+ # Also set where it might already exist but be empty
+ sed -i '' "s/DEVELOPMENT_TEAM = \"\";/DEVELOPMENT_TEAM = $DEVELOPMENT_TEAM;/g" "$PBXPROJ"
+ sed -i '' "s/DEVELOPMENT_TEAM = ;/DEVELOPMENT_TEAM = $DEVELOPMENT_TEAM;/g" "$PBXPROJ"
+fi
+
+# Create/Update entitlements file with App Group
+ENTITLEMENTS_FILE="ios/${APP_NAME}/${APP_NAME}.entitlements"
+if [ -n "$APP_GROUP" ]; then
+ echo " Setting APP_GROUP=$APP_GROUP"
+ cat > "$ENTITLEMENTS_FILE" << EOF
+
+
+
+
+ aps-environment
+ development
+ com.apple.security.application-groups
+
+ ${APP_GROUP}
+
+
+
+EOF
+ # Add CODE_SIGN_ENTITLEMENTS to pbxproj if not present
+ if ! grep -q "CODE_SIGN_ENTITLEMENTS" "$PBXPROJ"; then
+ sed -i '' "s/DEVELOPMENT_TEAM = $DEVELOPMENT_TEAM;/DEVELOPMENT_TEAM = $DEVELOPMENT_TEAM; CODE_SIGN_ENTITLEMENTS = ${APP_NAME}\\/${APP_NAME}.entitlements;/g" "$PBXPROJ"
+ fi
+fi
+
+echo "✅ Signing configured automatically"
+
+# (Old manual step - commented out)
+# open "$XCODE_PROJ"
+# echo "========================================================"
+# echo " [ACTION REQUIRED] "
+# echo " Xcode opened ($XCODE_PROJ)."
+# echo " 1. Go to 'Signing & Capabilities' tab."
+# echo " 2. Select your Team."
+# echo " 3. Verify 'App Clip' target is gone."
+# echo " 4. Ensure no red errors exist."
+# echo " Press ENTER here once you are done to continue building."
+# echo "========================================================"
+# read
# 5. Run
echo "5. Building and Running..."