Sin descripción

AppMarketingLinks.swift 2.5KB

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