readIOSBundleID reads the bundle ID from iOS project files (pbxproj then Info.plist).
(dir string)
| 522 | |
| 523 | // readIOSBundleID reads the bundle ID from iOS project files (pbxproj then Info.plist). |
| 524 | func readIOSBundleID(dir string) string { |
| 525 | // Flutter path. |
| 526 | if data, err := os.ReadFile(filepath.Join(dir, "ios", "Runner.xcodeproj", "project.pbxproj")); err == nil { |
| 527 | if id := extractPbxprojBundleID(string(data)); id != "" { |
| 528 | return id |
| 529 | } |
| 530 | } |
| 531 | // Native Xcode projects place the .xcodeproj at the root of the repo. |
| 532 | if entries, err := os.ReadDir(dir); err == nil { |
| 533 | for _, e := range entries { |
| 534 | if e.IsDir() && strings.HasSuffix(e.Name(), ".xcodeproj") { |
| 535 | pbx := filepath.Join(dir, e.Name(), "project.pbxproj") |
| 536 | if data, err := os.ReadFile(pbx); err == nil { |
| 537 | if id := extractPbxprojBundleID(string(data)); id != "" { |
| 538 | return id |
| 539 | } |
| 540 | } |
| 541 | } |
| 542 | } |
| 543 | } |
| 544 | if data, err := os.ReadFile(filepath.Join(dir, "ios", "Runner", "Info.plist")); err == nil { |
| 545 | if id := extractInfoPlistBundleID(string(data)); id != "" { |
| 546 | return id |
| 547 | } |
| 548 | } |
| 549 | return "" |
| 550 | } |
| 551 | |
| 552 | // pbxprojBundleIDRegex matches PRODUCT_BUNDLE_IDENTIFIER = com.example.app; in project.pbxproj. |
| 553 | var pbxprojBundleIDRegex = regexp.MustCompile(`PRODUCT_BUNDLE_IDENTIFIER\s*=\s*([a-zA-Z][a-zA-Z0-9._-]*)\s*;`) |