Bez popisu

AppMarketingLinks.swift 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // AppMarketingLinks.swift
  3. // App for Indeed
  4. //
  5. import Foundation
  6. /// Mac App Store URLs for Settings → Share App / More Apps.
  7. /// Override via build settings: `INFOPLIST_KEY_AppStoreAppID` and `INFOPLIST_KEY_AppStoreDeveloperID`.
  8. enum AppMarketingLinks {
  9. /// Canonical app name; keep in sync with `INFOPLIST_KEY_CFBundleDisplayName` in the Xcode target.
  10. static let displayName = "App for Indeed"
  11. /// Indeed® brand mark — always Latin “Indeed”, never transliterated in UI.
  12. static let indeedBrandName = "Indeed"
  13. /// Numeric App Store app ID from App Store Connect (e.g. `1234567890`).
  14. static var macAppStoreURL: URL? {
  15. guard let appID = resolvedAppStoreAppID else { return nil }
  16. return URL(string: "https://apps.apple.com/app/id\(appID)")
  17. }
  18. /// Developer catalog on the App Store (other apps by the same publisher).
  19. static var developerAppsURL: URL? {
  20. guard let developerID = resolvedAppStoreDeveloperID else { return nil }
  21. return URL(string: "https://apps.apple.com/developer/-/id\(developerID)")
  22. }
  23. static var appDisplayName: String {
  24. if let display = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String,
  25. !display.isEmpty {
  26. return display
  27. }
  28. if let name = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String,
  29. !name.isEmpty {
  30. return name
  31. }
  32. return displayName
  33. }
  34. static var shareText: String {
  35. let name = appDisplayName
  36. if let url = macAppStoreURL {
  37. return "Check out \(name) on the Mac App Store:\n\(url.absoluteString)"
  38. }
  39. return "Check out \(name) on the Mac App Store."
  40. }
  41. static var shareEmailSubject: String {
  42. "Check out \(appDisplayName)"
  43. }
  44. /// Payload for `NSSharingServicePicker` (Mail, Messages, AirDrop, Notes, Copy Link, etc.).
  45. static var shareItems: [Any] {
  46. var items: [Any] = [shareText as NSString]
  47. if let url = macAppStoreURL {
  48. items.append(url)
  49. }
  50. return items
  51. }
  52. static var isConfigured: Bool {
  53. macAppStoreURL != nil
  54. }
  55. private static var resolvedAppStoreAppID: String? {
  56. normalizedID(from: Bundle.main.object(forInfoDictionaryKey: "AppStoreAppID"))
  57. }
  58. private static var resolvedAppStoreDeveloperID: String? {
  59. normalizedID(from: Bundle.main.object(forInfoDictionaryKey: "AppStoreDeveloperID"))
  60. }
  61. private static func normalizedID(from value: Any?) -> String? {
  62. guard let raw = value as? String else { return nil }
  63. let trimmed = raw.trimmingCharacters(in: .whitespacesAndNewlines)
  64. guard !trimmed.isEmpty else { return nil }
  65. return trimmed
  66. }
  67. }