直接在终端运行,批量修改pbxproj文件中类的UDID。
python3 - <<'PYCODE'
import os, re, secrets, shutil
root = "/Users/henry/Desktop/xxx-mobile-ios"
pattern = re.compile(r'\b[A-F0-9]{24}\b')
count_total = 0
for dirpath, dirnames, filenames in os.walk(root):
if any(x in dirpath for x in ["Pods", "Vendor", "third_party"]):
continue
for name in filenames:
if not name.endswith(".pbxproj"):
continue
path = os.path.join(dirpath, name)
with open(path, "r", encoding="utf-8", errors="ignore") as f:
content = f.read()
matches = set(pattern.findall(content))
if not matches:
continue
new_content = content
for old in matches:
new = secrets.token_hex(12).upper() # 24位HEX
new_content = new_content.replace(old, new)
count_total += 1
shutil.copy2(path, path + ".bak")
with open(path, "w", encoding="utf-8") as f:
f.write(new_content)
print(f"✅ 已修改 {path} (共 {len(matches)} 个UUID)")
print(f"\n🎯 总计替换 {count_total} 处 UUID(Pods 等目录已跳过)")
PYCODE