AppConstants.swift 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // LoopFollow
  2. // AppConstants.swift
  3. import Foundation
  4. // Class that contains general constants used in different classes
  5. class AppConstants {
  6. static let APP_GROUP_ID = "group.com.$(unique_id).LoopFollow"
  7. /// Extracts the app suffix from the bundle identifier
  8. /// Bundle identifier format: com.$(unique_id).LoopFollow$(app_suffix)
  9. /// Returns the suffix part (e.g., "2" for "com.example.LoopFollow2")
  10. static var appSuffix: String {
  11. guard let bundleId = Bundle.main.bundleIdentifier else {
  12. return ""
  13. }
  14. // Extract suffix from bundle identifier
  15. // Pattern: com.$(unique_id).LoopFollow$(app_suffix)
  16. let pattern = "LoopFollow(.+)$"
  17. if let regex = try? NSRegularExpression(pattern: pattern) {
  18. let range = NSRange(location: 0, length: bundleId.utf16.count)
  19. if let match = regex.firstMatch(in: bundleId, options: [], range: range) {
  20. let suffixRange = match.range(at: 1)
  21. if let swiftRange = Range(suffixRange, in: bundleId) {
  22. let suffix = String(bundleId[swiftRange])
  23. return suffix.isEmpty ? "" : "_\(suffix)"
  24. }
  25. }
  26. }
  27. return ""
  28. }
  29. /// Returns a unique identifier for this app instance based on the app suffix
  30. static var appInstanceId: String {
  31. return "LoopFollow\(appSuffix)"
  32. }
  33. }