Keine Beschreibung

AppMarketingLinks.swift 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. /// Numeric App Store app ID from App Store Connect (e.g. `1234567890`).
  12. static var macAppStoreURL: URL? {
  13. guard let appID = resolvedAppStoreAppID else { return nil }
  14. return URL(string: "https://apps.apple.com/app/id\(appID)")
  15. }
  16. /// Developer catalog on the App Store (other apps by the same publisher).
  17. static var developerAppsURL: URL? {
  18. guard let developerID = resolvedAppStoreDeveloperID else { return nil }
  19. return URL(string: "https://apps.apple.com/developer/-/id\(developerID)")
  20. }
  21. static var appDisplayName: String {
  22. if let display = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String,
  23. !display.isEmpty {
  24. return display
  25. }
  26. if let name = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String,
  27. !name.isEmpty {
  28. return name
  29. }
  30. return displayName
  31. }
  32. static var shareText: String {
  33. let name = appDisplayName
  34. if let url = macAppStoreURL {
  35. return "Check out \(name) on the Mac App Store:\n\(url.absoluteString)"
  36. }
  37. return "Check out \(name) on the Mac App Store."
  38. }
  39. static var shareEmailSubject: String {
  40. "Check out \(appDisplayName)"
  41. }
  42. /// Payload for `NSSharingServicePicker` (Mail, Messages, AirDrop, Notes, Copy Link, etc.).
  43. static var shareItems: [Any] {
  44. var items: [Any] = [shareText as NSString]
  45. if let url = macAppStoreURL {
  46. items.append(url)
  47. }
  48. return items
  49. }
  50. static var isConfigured: Bool {
  51. macAppStoreURL != nil
  52. }
  53. private static var resolvedAppStoreAppID: String? {
  54. normalizedID(from: Bundle.main.object(forInfoDictionaryKey: "AppStoreAppID"))
  55. }
  56. private static var resolvedAppStoreDeveloperID: String? {
  57. normalizedID(from: Bundle.main.object(forInfoDictionaryKey: "AppStoreDeveloperID"))
  58. }
  59. private static func normalizedID(from value: Any?) -> String? {
  60. guard let raw = value as? String else { return nil }
  61. let trimmed = raw.trimmingCharacters(in: .whitespacesAndNewlines)
  62. guard !trimmed.isEmpty else { return nil }
  63. return trimmed
  64. }
  65. }